【问题标题】:"Server Error" with G+ API on APP engineAPP 引擎上的 G+ API 出现“服务器错误”
【发布时间】:2013-11-02 23:17:23
【问题描述】:

我的应用引擎上的 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

【问题讨论】:

  • 您需要查看日志中出现的错误。
  • 这里是日志文件:pastebin.com/APZyUaEV
  • 你的这行日志有点告诉PHP Fatal error: Uncaught exception 'Exception' with message 'Google CurlIO client requires the CURL PHP extension'我对PHP一无所知,但有人会认为你需要解决这些异常。

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


【解决方案1】:

按照说明设置 Google API 客户端 here

【讨论】:

    【解决方案2】:

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

    此外,在 GAE 上,urlfetch 似乎比 cURL 更受欢迎。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 2015-07-27
      • 2020-11-22
      • 2017-07-06
      • 2016-11-22
      相关资源
      最近更新 更多