【发布时间】:2017-10-12 06:03:01
【问题描述】:
我是 php 和 OAuth 的新手。使用代码登录和重定向是成功的。也可以通过这个获取访问令牌。
if (isset($_GET['code'])) {
$code = $_GET['code'];
$url = 'https://accounts.google.com/o/oauth2/token';
$params = array(
"code" => $code,
"client_id" => '123456789-123456789.apps.googleusercontent.com',
"client_secret" => '4tyajnbsd_fgjkhlkitu',
"redirect_uri" => 'https://example.com/loader/land.php',
"grant_type" => "authorization_code"
);
$ch = curl_init();
curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
$output = curl_exec($ch);
echo $output['access_token']; // not working to output only access token
$info = curl_getinfo($ch);
curl_close($ch);
}
但我对 OAuth 很陌生,无法仅通过
获得访问令牌echo $output['access_token'];
在该输出之后 php 也会死掉,并且无法继续使用我现有的代码。对我来说很难找到。我只是一个初学者。请帮我继续。我需要为其他剩余进程获取 access_token。非常感谢您。
【问题讨论】:
-
var_dump($output) ?
-
@AZinkey,它返回“bool(true)”。请问如何继续?
-
整个代码都在一个函数中吗?因为有一个
return但实际上我看不到任何函数定义。 -
@Twinfriends,嗨,我从 SO 复制了该代码,这可能是主要原因吗?请你帮我修一下。谢谢。