< /ul>
Код: Выделить всё
$oauth = new Google_Service_Oauth2($client);
$userinfo = $oauth->userinfo->get();
< /ul>
Код: Выделить всё
stdClass#1
(
[access_token] => '{TOKEN}'
[expires_in] => 3599
[refresh_token] => '{REFRESH_TOKEN}'
[scope] => 'https://www.googleapis.com/auth/blogger https://www.googleapis.com/auth/userinfo.profile'
[token_type] => 'Bearer'
[id_token] => '{ID_TOKEN}'
)
< /code>
Я могу отлично получить информацию о блогере и контент в Google Playground, когда я введу Access_token, которую я получил, используя поток OAuth на моем сервере. Таким образом, access_token
У вашего клиента нет
разрешения на получение URL /V3 /blogs /byurl < /code> с этого сервера. Это все, что мы знаем.
Код: Выделить всё
$client = new \Google_Client();
$client->setClientId({ID});
$client->setClientSecret({SECRET});
$client->setRedirectUri({CALLBACK_URL});
$client->setAccessType('offline');
$client->setPrompt('consent');
$client->addScope([
'https://www.googleapis.com/auth/blogger',
'https://www.googleapis.com/auth/userinfo.profile',
]);
$authUrl = $client->createAuthUrl();
$this->redirect($authUrl);
< /code>
обработка обратного вызова: < /p>
if (!isset($_GET['code'])) {
throw new CHttpException(400, 'No code provided');
}
$client->setClientId({ID});
$client->setClientSecret({SECRET});
$client->setRedirectUri({CALLBACK_URL});
$client->setAccessType('offline');
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
if (isset($token['error'])) {
throw new CHttpException(400, 'Google auth error: ' . $token['error_description']);
}
// For test purposes the token is just saved to session instead of DB
Yii::app()->session['google_token'] = $token;
$client->setAccessToken($token);
$oauth = new Google_Service_Oauth2($client);
// This works. An object with the user information is returned
$userinfo = $oauth->userinfo->get();
$service = new Google_Service_Blogger($client);
// this doesn't work and returns the 403 error
$blogs = $service->blogs->getByUrl([
'url'=> '{BLOG_URL}'
]);
$client = new \GuzzleHttp\Client();
$res = $client->get('https://www.googleapis.com/blogger/v3/users/self/blogs', [
'headers' => [
'Authorization' => 'Bearer {ACCESS_TOKEN}'
]
]);
/// returns 403
echo $res->getBody();
< /code>
Я действительно потерян. В моей панели Google Cloud Console нет уведомлений. Кажется, что API блоггера только что сломался без предупреждения. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/796 ... ng-anymore