在对用户进行身份验证时,我如何获取用户 ID 以便我列出他们的博客。
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_BloggerService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName('Blogger');
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$client->setDeveloperKey('insert_your_simple_api_key');
$blogger = new Google_BloggerService($client);
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
var_dump($blogger->blogs->listByUser("USER_ID_HERE")); //how do i get the user id?
} else {
$authUrl = $client->createAuthUrl();
print "<a href='$authUrl'>Connect Me!</a>";
}
该文档是无用的,它显示的只是如何使用未知数(即 blogID、postID 等)获取博客帖子等,以便能够获取 blogID、postID 我需要身份验证时未提供的初始用户 ID。