Ahmed Sherif
Ahmed Sherif

Reputation: 180

"Server Error" with G+ API on APP engine

I've a problem with Google+ API on my app engine .

I tried my codes on my own hosting and it worked well , I don't know why it gives me a server error when I deploy my code on the app engine .

Firstly here's the G+ code with file named (index.php) :

<?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>";
}

Also Here's the app.yaml configuration :

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

handlers:
- url: /
  script: index.php

I put all API library on the same directory of app engine files , but when I access to my app engine link it gives me "Server Error"

gcdc2013-troubles.appspot.com

Upvotes: 0

Views: 195

Answers (2)

Stuart Langley
Stuart Langley

Reputation: 7054

Follow the instructions for setting up the Google API client here.

Upvotes: 1

momo
momo

Reputation: 3474

Did you include/uncomment extension=php_curl.dll in your php.ini?

Also, it looks like urlfetch is preferred over cURL on GAE.

Upvotes: 0

Related Questions