Hello all,
I'm having an issue with the gmail api.
I'm using this php code straight off google code:
It includes Zend for IMAP access.
The above code works just fine if I generate an access token using oauth2.py (as advertised):
But if i try to generate an access token using apiClient.php (from the standard google-api-php-client):
and inserting that into Zend's IMAP request, i get connection fail.
The access token is generated (i echo it and it's there), but when i try to connect with Zend's IMAP to google, it's just going to output connection failed.
Some code for clarification (some fields hidden for security reasons):
//STANDARD GOOGLE API CONNECT
$client = new apiClient();
$client->setApplicationName("GMail App");
$client->setClientId('HIDDEN');
$client->setClientSecret('HIDDEN');
$client->setDeveloperKey('HIDDEN');
//MY EMAIL
//I GET THE ACCESS TOKEN, I CONVERT IT TO UTF-8, AND THEN I JSON DECODE IT
$tok = json_decode(mb_convert_encoding($client->getAccessToken(), 'utf-8'));
$tok2 = $tok->{'access_token'};
// $oauth2py = 'ACCESS TOKEN FROM OAUTH2.PY WHICH WORKS';
tryImapLogin($email, $tok2);
/**
* Make the IMAP connection and send the auth request
*/
function tryImapLogin($email, $accessToken) {
if (oauth2Authenticate($imap, $email, $accessToken)) {
echo '<h1>Successfully authenticated!</h1>';
showInbox($imap);
} else {
echo '<h1>Failed to login</h1>';
}
}
You can test it out for yourself here:
If instead of:
tryImapLogin($email, $tok2);
i generate an auth code using oauth2.py and i call:
tryImapLogin($email, $oauth2py);
it works!
Any help would be immensely appreciated!
Adrian.