Service Account error

433 views
Skip to first unread message

Alessandro

unread,
Apr 14, 2012, 5:24:39 AM4/14/12
to google-api...@googlegroups.com
Hey Chirag,

I checked out rev412 from trunk of Google PHP client for API. I'm using prediction/serviceAccount.php example (with service changed to shopping API as in shopping/simple.php)

on my local developer server: php 5.2.17 on Apache 2.0 on windows 7

I have error :
Warning: openssl_sign() expects parameter 4 to be long, string given in ....src\auth\apiP12Signer.php on line 60
(as on php manual, where there seems to be no support for sha256 algo in some versions)

Trying to use default algo takes me to this problem:
Uncaught exception 'apiAuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'' in .....src\auth\apiOAuth2.php:
276 Stack trace: #0 .....\src\auth\apiOAuth2.php(253): apiOAuth2->refreshTokenRequest(Array) #1 ...\src\auth\apiOAuth2.php(206): apiOAuth2->refreshTokenWithAssertion() #2 .....\src\service\apiServiceResource.php(167): apiOAuth2->sign(Object(apiHttpRequest)) #3 .....\src\contrib\apiShoppingService.php(91): apiServiceResource->__call('list', Array) #4 ...... in ......\src\auth\apiOAuth2.php on line 276

Is there a specific php version(s) supported by the spi-php-client?

Alessandro


_____________________________________________php code_____________________________

require_once '....../src/apiClient.php';
require_once '....../src/contrib/apiShoppingService.php';

define('KEY_FILE', 'my key file );
define('SERVICE_ACCOUNT_NAME', '???');
define('CLIENT_ID', 'my client ID');


$client = new apiClient();
$client->setApplicationName("Google Shopping Sample");

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

$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new apiAssertionCredentials(
  SERVICE_ACCOUNT_NAME,
  array('https://www.googleapis.com/auth/structuredcontent'),
  $key)
);

$client->setClientId(CLIENT_ID);

// Visit https://code.google.com/apis/console?api=shopping to generate your
// Simple API Key.
$client->setDeveloperKey('my developer key');
$service = new apiShoppingService($client);

$source = "gan:xxxxxxx";


// For more information about full text search with the shopping API, please
// see http://code.google.com/apis/shopping/search/v1/getting_started.html#text-search
$query = "\"mp3 player\" | ipod";

$ranking = "relevancy";
$results = $service->products->listProducts($source, array(
  "country" => "US",
  "q" => $query,
  "rankBy" => $ranking,
));

print "<h1>Shopping Results</h1><pre>" . print_r($results, true) . "</pre>";

// We're not done yet. Remember to update the cached access token.
// Remember to replace $_SESSION with a real database or memcached.
if ($client->getAccessToken()) {
  $_SESSION['token'] = $client->getAccessToken();

Chirag Shah

unread,
Apr 16, 2012, 6:43:45 PM4/16/12
to google-api...@googlegroups.com
Hi Alessandro,

Thank you for reporting this issue! It appears that openssl_sign's optional signature_alg parameter accepts a string in PHP 5.3.0, but wasn't patched into 5.2.

Would it be possible for you to upgrade from 5.2.17 to the stable version of 5.3? I will work detecting this error case inside apiP12Signer, and surfacing an appropriate error message.

Thank you,
Chirag

Alessandro

unread,
Apr 18, 2012, 9:52:22 AM4/18/12
to google-api...@googlegroups.com
Thank you Chirag for your answer,
I have upgraded the developer server to php 5.3.10 and it works ok.
Now I'll try to have the production server upgraded (not on my direct control).

I have found many difficulties in making all work, NOT directly about the google-client-php-api library, but regarding the GAN / API access / oAuth2 / shopping API settings which are required to access (as a publisher) the GAN products through the APIs.
I think it is needed to have a step by step example, don't know if you can suggest it to the documentation personnel of google.

I'll make a post giving some hints to help other developers.

Thank you,
Alessandro


Chirag Shah

unread,
Apr 26, 2012, 3:51:10 PM4/26/12
to google-api...@googlegroups.com
On Wed, Apr 18, 2012 at 6:52 AM, Alessandro <affi...@achoiceforyou.com> wrote:
Thank you Chirag for your answer,
I have upgraded the developer server to php 5.3.10 and it works ok.
Now I'll try to have the production server upgraded (not on my direct control).

I have found many difficulties in making all work, NOT directly about the google-client-php-api library, but regarding the GAN / API access / oAuth2 / shopping API settings which are required to access (as a publisher) the GAN products through the APIs.
I think it is needed to have a step by step example, don't know if you can suggest it to the documentation personnel of google.

Makes sense. We do have some documentation over here about the GAN API:

But, it doesn't contain a step by step example.
 

I'll make a post giving some hints to help other developers.

Many thanks for this! I'd like to take a look at too!
 

Thank you,
Alessandro



Alessandro

unread,
Apr 27, 2012, 3:48:03 AM4/27/12
to google-api...@googlegroups.com
Hi Chirag!

I've posted on https://groups.google.com/forum/#!topic/google-search-api-for-shopping/fDn8d5-lzkk
just a few hints.

Have a nice day!
Alessandro
Reply all
Reply to author
Forward
0 new messages