dougua3705 2014-10-28 19:58
浏览 119

为什么我的Google OAuth 2.0不起作用?

I've been working on a small script to grab YouTube channel data and my Google OAuth 2.0 isn't working.

$validate = "https://accounts.google.com/o/oauth2/auth?client_id=242340718758-65veqhhdjfl21qc2klkfhbcb19rre8li.apps.googleusercontent.com&redirect_uri=http://conor1998.web44.net/php/oauth.php&scope=https://www.googleapis.com/auth/yt-analytics.readonly&response_type=code&access_type=offline";

echo "<a href='$validate'>Login with Google for advanced analytics</a>";

if(isset($_GET['code'])) {
    // try to get an access token
    $code = $_GET['code'];
    $url = 'https://accounts.google.com/o/oauth2/token?code='.$code.'&client_id=242340718758-65veqhhdjfl21qc2klkfhbcb19rre8li.apps.googleusercontent.com&client_secret={secret}&redirect_uri=http://conor1998.web44.net/php/oauth.php&grant_type=authorization_code';
    $url = urlencode($url);
    header('Location: $url');
}


$response = file_get_contents($url);
$response = json_decode($response);



$channel_data = file_get_contents('https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==mine&start-date=2014-08-01&end-date=2014-09-01&metrics=views&key=AIzaSyDTxvTLWXStUrhzgCDptVUG4dGBCpyL9MY?alt=json');
$channel_data = json_decode($channel_data, true);

echo "<br />";
var_dump($channel_data);
echo "<br />";

I have no idea why it doesn't work. I feel it's mainly due to my goal of trying to get the authentication token for the user so i can grab their YouTube data. Any help would be appreciated

  • 写回答

1条回答 默认 最新

  • duanmin0941 2014-10-29 10:00
    关注

    The code you receive from the auth website is not the access token! You have to exchange it for refresh and access tokens (see #4).

    You have to perform a POST request to https://accounts.google.com/o/oauth2/token in order to get your tokens. It is not working via GET (as you can see when clicking the link).

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型