İşte bulduğum çözüm.
Normalde Anahtar P12 için, bir belirteç oluşturmak için aşağıdaki kodu kullanabilirsiniz.
JSON Anahtar için
public static function getToken()
{
$key = file_get_contents(APPLICATION_DIR.'/'.APPLICATION_GOOGLE_CLIENT_KEY_FILE);
$cred = new Google_Auth_AssertionCredentials(
APPLICATION_GOOGLE_CLIENT_EMAIL,
array('https://spreadsheets.google.com/feeds'),
$key
);
$client = new Google_Client();
$client->setAssertionCredentials($cred);
if (!$client->getAuth()->isAccessTokenExpired()) {
return false;
}
else {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service_token = json_decode($client->getAccessToken());
return $service_token->access_token;
}
Ama şimdi P12 anahtarı yok, bir JSON anahtarı var, bu yüzden sadece yukarıdaki kodda bazı değişiklikler yapılmış, aşağıda bir göz atın lütfen:
public static function getToken()
{
$key = APPLICATION_DIR.'/'.APPLICATION_GOOGLE_CLIENT_KEY_FILE;
$data = json_decode(file_get_contents($key)); // here i decoded the json
if (isset($data->type) && $data->type == 'service_account') {
$cred = new Google_Auth_AssertionCredentials(
APPLICATION_GOOGLE_CLIENT_EMAIL, // it's the client email
array('https://spreadsheets.google.com/feeds'), // it's google spreadsheet scope
$data->private_key // here is the private key
);
}
$client = new Google_Client();
$client->setAssertionCredentials($cred);
if (!$client->getAuth()->isAccessTokenExpired()) {
return false;
}
else {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service_token = json_decode($client->getAccessToken());
return $service_token->access_token;
}
JSON anahtarı oluşturma talimatlarını takip ettiniz mi? – tam5
Uygulamanızı gösterebilir misiniz? – yergo
@Insomania hala bunun üzerinde çalışıyor musunuz? – Twisty