I am using Yii and the google API for yii from here yii google api. I want to fetch the contact list with this api but this is throwing the error
stdClass Object ( [error] => invalid_grant [error_description] => Code was already redeemed. )
I am using like this
public function actionIndex()
{
$client = Yii::app()->GoogleApis->client;
$client -> setAccessType('online');
$client -> setScopes('https://www.google.com/m8/feeds');
$client->authenticate();
if (isset($_GET['code'])) {
$auth_code = $_GET["code"];
Yii::app()->session['auth_token']= $auth_code;
$this->redirect(array('/addcontacts/searchsuggesions'));
}
$this->render('index');
}
public function actionSearchsuggesions()
{
if(Yii::app()->session['auth_token'])
{
$auth_code = Yii::app()->session['auth_token'];
$max_results = 200;
$fields=array(
'code'=> urlencode($auth_code),
'client_id'=> urlencode('**********'),
'client_secret'=> urlencode('**********'),
'redirect_uri'=> urlencode('http://localhost/addcontacts'),
'grant_type'=> urlencode('authorization_code')
);
$post = '';
foreach($fields as $key=>$value)
{
$post .= $key.'='.$value.'&';
}
$post = rtrim($post,'&');
$result = $this->curl('https://accounts.google.com/o/oauth2/token',$post);
$response = json_decode($result);
print_r($response);die;
}
}
i don't know where i am wrong . if someone have clue please tell me .