sscarpa / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

Error when granularity="best" in Latitude service #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a script with this content :

<?php

    require_once "../../src/apiClient.php";
    require_once "../../src/contrib/apiLatitudeService.php";

    require_once "includes/header.php";

    $apiClient = new apiClient();
    $lat = new apiLatitudeService($apiClient);

    if (isset($_SESSION['auth_token'])) {
      $apiClient->setAccessToken($_SESSION['auth_token']);
    } else {
      $_SESSION['auth_token'] = $apiClient->authenticate();
    }

    $latitude1 = $lat->getCurrentLocation('city');

    echo "<pre>";
    print_r($latitude1);
    echo "</pre>";

    $latitude2 = $lat->getCurrentLocation('best');

    echo "<pre>";
    print_r($latitude2);
    echo "</pre>";

?>

2. Execute the script and look the result

What is the expected output? What do you see instead?
The result to the line "$latitude1 = $lat->getCurrentLocation('city');" works, 
the position is returned, but
the line "$latitude2 = $lat->getCurrentLocation('best');" return an error :
Fatal error: Uncaught exception 'apiServiceException' with message 'Error 
calling 
https://www.googleapis.com/latitude/v1/currentLocation?granularity=best&alt=json
: (401) Invalid Credentials' in 
/home/www/9d39bf010a3c15d51e47350ba58958ce/web/src/io/apiREST.php:85 Stack 
trace: #0 
/home/www/9d39bf010a3c15d51e47350ba58958ce/web/src/service/apiServiceResource.ph
p(101): apiREST::execute(Object(apiServiceRequest)) #1 
/home/www/9d39bf010a3c15d51e47350ba58958ce/web/src/contrib/apiLatitudeService.ph
p(115): apiServiceResource->__call('get', Array) #2 
/home/www/9d39bf010a3c15d51e47350ba58958ce/web/examples/latitude/getLatitude.php
(30): apiLatitudeService->getCurrentLocation('best') #3 {main} thrown in 
/home/www/9d39bf010a3c15d51e47350ba58958ce/web/src/io/apiREST.php on line 85

What version of the product are you using? On what operating system?
Library version: google-api-php-client 0.2
OS: Linux

Please provide any additional information below.

Original issue reported on code.google.com by david.an...@gmail.com on 21 Jan 2011 at 5:51

GoogleCodeExporter commented 8 years ago
Hello,

I've just tested your script on my localhost with WAMP. My result is that I've 
been redirected to this page :
https://www.google.com/latitude/b/0/apps?latitudeAuthResponse=INVALID_REQUEST_PA
RAMS

Do I have to specify an ApiKey or something ?

Original comment by jgarnie...@gmail.com on 28 Apr 2011 at 10:40

GoogleCodeExporter commented 8 years ago
My knowledge of this is pretty minimal (I've learned just enough to do what I 
need to do...) but my understanding is you need to authorise the request with 
an OAuth access token. Your code structure differs from mine, but maybe you'll 
get the idea?

if(!$accessToken=unserialize(file_get_contents('/home/lee/latitude/token.txt')))
 die('Unable to read access token.');
$client = $accessToken->getHttpClient($oauthOptions);

My token is stored in a text file, that is then read each time the script runs 
to pull location data.

Original comment by lee.smal...@gmail.com on 28 Apr 2011 at 5:36

GoogleCodeExporter commented 8 years ago
I am having the same problem :

https://www.google.com/latitude/b/0/apps?latitudeAuthResponse=INVALID_REQUEST_PA
RAMS

Original comment by 50Pix....@gmail.com on 17 Jun 2011 at 1:52

GoogleCodeExporter commented 8 years ago
Is your token authorised to use 'best' ? There are 2 request types, city and 
best. Your token needs to have the right authority.

Original comment by lee.smal...@gmail.com on 17 Jun 2011 at 4:29

GoogleCodeExporter commented 8 years ago
Now after I'm authorized and redirected back to my site I get the following : 

Fatal error: Uncaught exception 'apiCacheException' with message 'Cache file 
could not be deleted' in 
/var/www/sites/web2era/public_html/googleapi/src/cache/apiFileCache.php:132 
Stack trace: #0 
/var/www/sites/web2era/public_html/googleapi/src/auth/apiOAuth.php(76): 
apiFileCache->delete('OAuth:anonymous...') #1 
/var/www/sites/web2era/public_html/googleapi/src/apiClient.php(130): 
apiOAuth->authenticate(Object(apiFileCache), Object(apiCurlIO), Array) #2 
/var/www/sites/web2era/public_html/googleapi/examples/index.php(37): 
apiClient->authenticate() #3 {main} thrown in 
/var/www/sites/web2era/public_html/googleapi/src/cache/apiFileCache.php on line 
132 

you can test it at : 

http://web2era.com/googleapi/examples/

Original comment by lickstr....@gmail.com on 17 Jun 2011 at 7:15

GoogleCodeExporter commented 8 years ago
I am having the same problem  401  Invalid Credentials . . (This is a new 
problem) It was working before there's something Wrong @ google's Side . . 

Original comment by shehabic on 18 Jun 2011 at 1:28

GoogleCodeExporter commented 8 years ago
I think comment #4 above is correct.  I have seen a similar error because the 
token was authorized with an improper scope.  

In src/config.php i changed the scope for latitude to .all.best and that fixed 
the error.  Other scopes are likely appropriate for different uses.

Original comment by krkee...@gmail.com on 17 Aug 2011 at 11:17

GoogleCodeExporter commented 8 years ago
It looks like the latitude API deprecated the 
https://www.googleapis.com/auth/latitude scope and replaced it with the 
following scopes:
   https://www.googleapis.com/auth/latitude.all.best
   https://www.googleapis.com/auth/latitude.all.city

I've included these scopes in the latest version of the client library, see 
http://code.google.com/p/google-api-php-client/source/browse/trunk/src/config.ph
p#63

If you want to use granularity="best", you'll need to use the scope 
'https://www.googleapis.com/auth/latitude.all.best'

Original comment by chirags@google.com on 31 Aug 2011 at 4:56

GoogleCodeExporter commented 8 years ago
Issue 8 has been merged into this issue.

Original comment by chirags@google.com on 31 Aug 2011 at 4:57