0

我的应用引擎上的 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 库放在应用程序引擎文件的同一目录中,但是当我访问我的应用程序引擎链接时,它给了我“服务器错误”

gcdc2013-troubles.appspot.com

4

2 回答 2

1

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

于 2013-11-03T10:11:22.043 回答
0

extension=php_curl.dll您是否在您的? 中包含/取消注释php.ini

此外,它看起来urlfetchcURLGAE 更受欢迎。

于 2013-11-03T09:29:21.077 回答