正如这里提到的错误:
调用 GET https://www.googleapis.com/plus/v1/people/me?key=MYKEY时出错:(403) 请求未指定任何引用者。请确保客户端发送referer或使用API控制台删除referer限制
我的代码:
$client = new Google_Client();
$client->setApplicationName("maaa");
//$client->setHttpClient($httpClient);
echo "login 2";
// Visit https://code.google.com/apis/console?api=plus to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri($callbackurl);
$client->setDeveloperKey(GOOGLE_API_KEY);
$client->setAccessType("online");
$client->setApprovalPrompt("auto");
$plus = new Google_PlusService($client);
echo "login 3";
if (isset($_GET['code'])) {
echo "login inside....";
try {
$client->authenticate();
} catch(Exception $e) {
echo $e;
}
$token = $client->getAccessToken();
try {
$userProfile = $plus->people->get("me");
} catch(Exception $e) {
//ERROR Error calling GET https://www.googleapis.com/plus/v1/people/me?key=mYKEY: (403) The request did not specify any referer. Please ensure that the client is sending referer or use the API Console to remove the referer restrictions
echo $e;
}
$id = $userProfile['id'];
return array(
'user' => $id,
'network' => 'google',
'userprofile' => $userProfile,
'token' => $token,
'loginUrl' => null,
'logoutUrl' => null
);
} else {
$authUrl = $client->createAuthUrl();
return array(
'user' => 0,
'network' => 'google',
'userprofile' => $userProfile,
'token' => null,
'loginUrl' => $authUrl,
'logoutUrl' => null
);
}
以下是我的 api 的设置。如果我保持以下设置,那么一切都会很好,但如果我想保持对 HTTP 的限制,那么它将无法正常工作。如果有人知道让它工作而对 HTTP 选项没有任何问题,请告诉我。
谢谢,如果有人知道如何将推荐人发送给谷歌客户端,请告诉我.....