0

Hi friends I am learning GOOGLE API
I got error : Invalid Signature
Here my code
Any body have idea
And thx in Advance

function GetRequestToken()
	{
		$consumer = 'MY_CONSUMER KEY';
		$secret = 'MY_COSUMER_SECRETE';
		$callback = 'http://localhost/Gcontacts/welcome/redirection';
		$sign_method = 'HMAC-SHA1';
		$version = '1.0';
		$scope = 'https://www.google.com/m8/feeds/';
		$path = "/accounts/OAuthGetRequestToken";
		 
		$mt = microtime();
		$rand = mt_rand();
		$nonce = md5($mt.$rand);
		$time = time();
		
	
		$url = 'https://www.google.com/accounts/OAuthGetRequestToken';
		
		$post = array(
		    'oauth_callback' => $callback,
		    'oauth_consumer_key' => $consumer,
		    'oauth_nonce' => $nonce,
		    'oauth_signature_method' => $sign_method,
		    'oauth_timestamp' => $time,
		    'oauth_version' => $version,
		    'scope' => $scope
			);
		$post_string1 = '';
		foreach($post as $key => $value)
		{
    		$post_string1 .= $key.'='.($value).'&';
		}
		
		$post_string1 = trim($post_string1, '&');
		
		$key_part = $this->urlencodeRFC3986($secret);
		$key = $key_part;
			$base_string = $this->calculateBaseString($scope, "GET", $post);
			echo $base_string;
			$signature = base64_encode(hash_hmac('sha1', $base_string, $key,true));
			$post_string1 .= 'oauth_signature'.'='.urlencode($signature);
			$post['oauth_signature'] = $signature;
application/x-www-form-urlencoded ,Host: www.google.com';

			$header[] = 'POST'.$path.'?scope='.$scope.' HTTP/1.1';
			$header[] = 'Content-Type: application/x-www-form-urlencoded';
			$header[] = 'Accept: */*';			
			$header[] = $this->calculateHeader($post).', Content-Type: application/x-www-form-urlencoded ,Host: www.google.com';

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string1);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_POSTFIELDS, 'scope='.$scope);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
			
			$result = curl_exec($ch);
			curl_close($ch);
			echo "<pre>";
			print_r($result);
			echo "</pre>";
			exit;
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by paresh_thummar
0

did you go to google and generate your own key to be able to use the api ?

I registered my domain and i got consumer key and consumer secret
But I think problem may be in base string and i am not sure about it. So if you have any idea. Please.....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.