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).

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。