我正在使用谷歌的博客 API 制作应用程序。
我想要的是成功登录后我可以在博客点显示我拥有的所有博客,我在 blogspot 上有 2 个博客blog-api-test.blogspot.com和blog-api-test-2.blogspot.com
我已经使用以下代码成功登录,在这个项目中我使用 google-api-php-client 并使用提供的服务, 那么如何显示一个选项来选择我的两个博客?
我的简单代码
<?php
require 'init.php';
if (!$oauth_credentials = getOAuthCredentialsFile()) {
echo missingOAuth2CredentialsWarning();
return;
}
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->addScope(Google_Service_Blogger::BLOGGER);
$service = new Google_Service_Blogger($client);
if (isset($_GET['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
// store in the session also
$_SESSION['upload_token'] = $token;
// redirect back to the example
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
// set the access token as part of the client
if (!empty($_SESSION['upload_token'])) {
$client->setAccessToken($_SESSION['upload_token']);
if ($client->isAccessTokenExpired()) {
unset($_SESSION['upload_token']);
}
} else {
$authUrl = $client->createAuthUrl();
}
?>
<div class="box">
<?php if (isset($authUrl)): ?>
<div class="request">
<a class='login' href='<?= $authUrl ?>'>Login Now</a>
</div>
<?php endif ?>
</div>
或者我想让你们有一个教程?