在APP引擎上使用G + API的“服务器错误”

时间:2013-11-02 23:17:23

标签: php google-app-engine google-api-php-client

我的应用引擎上的Google+ API存在问题。

我在我自己的托管上尝试了我的代码并且运行良好,我不知道为什么当我在应用引擎上部署代码时它会给我一个服务器错误。

首先,这是带有名为(index.php)的文件的G +代码:

<?php


require_once 'Google_Client.php';
require_once 'Google_PlusService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Google+ PHP Starter Application");

//Visit https://code.google.com/apis/console?api=plus to generate your
//client id, client secret, and to register your redirect uri.
$client->setClientId('55845591562.apps.googleusercontent.com');
$client->setClientSecret('J-l4j5yxhVsCfrfRHVy1x8IF');
$client->setRedirectUri('http://fictionteam.com/fb/');
$client->setDeveloperKey('AIzaSyCNDNQn7A9M2COPaW1NOYpZEoaiXCNibZ4');
$plus = new Google_PlusService($client);

if (isset($_GET['logout'])) {
  unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
  if (strval($_SESSION['state']) !== strval($_GET['state'])) {
    die("The session state did not match.");
  }
  $client->authenticate();
  $_SESSION['token'] = $client->getAccessToken();
  $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
  $me = $plus->people->get('me');
  print "Your Profile: <pre>" . print_r($me, true) . "</pre>";

  $params = array('maxResults' => 100);
  $activities = $plus->activities->listActivities('me', 'public', $params);
  print "Your Activities: <pre>" . print_r($activities, true) . "</pre>";

  $params = array(
    'orderBy' => 'best',
    'maxResults' => '20',
  );
  $results = $plus->activities->search('Google+ API', $params);
  foreach($results['items'] as $result) {
    print "Search Result: <pre>{$result['object']['content']}</pre>\n";
  }

  // The access token may have been updated lazily.
  $_SESSION['token'] = $client->getAccessToken();
} else {
  $state = mt_rand();
  $client->setState($state);
  $_SESSION['state'] = $state;

  $authUrl = $client->createAuthUrl();
  print "<a class='login' href='$authUrl'>Connect Me!</a>";
}

此处还有app.yaml配置:

application: gcdc2013-troubles
version: 1
runtime: php
api_version: 1

handlers:
- url: /
  script: index.php

我将所有API库放在app引擎文件的同一目录中,但是当我访问我的app引擎链接时,它会给我“服务器错误”

gcdc2013-troubles.appspot.com

2 个答案:

答案 0 :(得分:1)

按照设置Google API客户端here的说明进行操作。

答案 1 :(得分:0)

您是否在extension=php_curl.dll中添加/取消注释php.ini

此外,GAE上的urlfetch似乎优先于cURL