FromDK / 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

Latitude Error Gives 401 Invalid Credential with anything #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Latiutude API gives 401 When trying to get current location or anything

What steps will reproduce the problem?
1.I'm authorized with oAuth normally for ( granularity=best & locaiton=current)
2.I'm redirected back to my site now when I try to fetch the currentlocation I 
get 401 Invalid credentials

What is the expected output? What do you see instead?
- the expected output is to get the location not 401 Error

What version of the product are you using? On what operating system?

v1 with any of the Client Libs provided by google 

Please provide any additional information below.

This is my Code both give the same error

<-------------- CODE 1 --------------->

<?php 

ini_set("display_errors",1);
error_reporting(E_ALL);
session_start(); 
// set_include_path('/home/library/'.get_include_path());
require_once 'Zend/Oauth/Consumer.php'; 

$oauthOptions = array(
    'requestScheme'        => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version'              => '1.0',
    'consumerKey'          => '################My Key###########',
    'consumerSecret'       => '################My Secret########',
    'signatureMethod'      => 'HMAC-SHA1',
    'requestTokenUrl'      => 'https://www.google.com/accounts/OAuthGetRequestToken',
    'userAuthorizationUrl' => 'https://www.google.com/latitude/apps/OAuthAuthorizeToken',
    'accessTokenUrl'       => 'https://www.google.com/accounts/OAuthGetAccessToken',
    'callbackUrl'          => 'http://web2era.com/googleapi/examples/',
);
$consumer = new Zend_Oauth_Consumer($oauthOptions); 
if (!isset($_SESSION['ACCESS_TOKEN_GOOGLE'])) { 
    if (!empty($_GET)) { 
        $token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN_GOOGLE'])); 
        $_SESSION['ACCESS_TOKEN_GOOGLE'] = serialize($token); 
    } else { 
        $token = $consumer->getRequestToken(array('scope'=>'https://www.googleapis.com/auth/latitude')); 
        $_SESSION['REQUEST_TOKEN_GOOGLE'] = serialize($token); 
        $customparams = array('domain' => 'web2era.com', 'granularity' => 'best', 'location' => 'current');
        $consumer->redirect($customparams ); 
        exit; 
    } 
} else { 
    $token = unserialize($_SESSION['ACCESS_TOKEN_GOOGLE']); 
    //$_SESSION['ACCESS_TOKEN_GOOGLE'] = null; // do not use, we want to keep the access token
} 
$client = $token->getHttpClient($oauthOptions); 
// I Use this
$client->setUri('https://www.googleapis.com/latitude/v1/currentLocation?granular
ity=best'); 
// Other times I use this
$client->setUri('https://www.googleapis.com/latitude/v1/currentLocation'); 
$client->addParameterGet("granularity","best");

$client->setMethod(Zend_Http_Client::GET); 

$response = $client->request(); 
$body = $response->getBody();
header('Content-Type: ' . $response->getHeader('Content-Type')); 
echo $response->getBody(); 

<-------------- Another Code That doesn't work tooo ------------->

session_start();
ini_set("display_errors","on");
require_once '../src/apiClient.php';
require_once '../src/contrib/apiBuzzService.php';
require_once '../src/contrib/apiLatitudeService.php';
global $apiConfig;
$apiConfig['oauth2_client_id'] = '######### Client ID ##########';
$apiConfig['oauth2_client_secret'] = '####### Secret #######';

// The oauth2_redirect_uri is typically the path to where you host this PHP 
file.
$apiConfig['oauth2_redirect_uri'] = 'http://web2era.com/googleapi/examples';
$apiconfig['authClass'] = 'apiOAuth2';

$apiClient = new apiClient();

$latitude = new apiLatitudeService($apiClient);

$apiClient->discover("latitude", "v1");

$latitude->setVersion("v1");

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

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

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

    echo $latitude1;

////
////  Notice the (almost) same code Works perfectly for Buzz
////

Original issue reported on code.google.com by shehabic on 18 Jun 2011 at 1:37

GoogleCodeExporter commented 8 years ago
Anybody there ?

Original comment by shehabic on 18 Jun 2011 at 11:54

GoogleCodeExporter commented 8 years ago
This issue tracker is really for the google api library it's self, and not for 
the product specific support.

https://groups.google.com/group/google-latitude-api?pli=1 is the right place to 
ask Latitude specific questions

Original comment by chabotc@google.com on 19 Jun 2011 at 12:03

GoogleCodeExporter commented 8 years ago

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