作者onininon (万)
看板PHP
标题[请益] PHP GET中有符号+
时间Fri Nov 11 17:32:46 2011
大家好:
我在使用google api OAuth2
使用了网路上写好的callback.php
http://ppt.cc/qJmC
$url =
"
https://accounts.google.com/o/oauth2/auth?".
http_build_query(array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'scope' => $scope,
'response_type' => 'code'
));
其中GET栏位中有个scope
http://ppt.cc/k-zE
如果想要帐号资料和email资料 需要在scope中加入
https://www.googleapis.com/auth/userinfo.profile+
https://www.googleapis.com/auth/userinfo.email
在callback.php中有$scope变数来存
结果连结变成
https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%2B
https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
导致OAuth 2.0 错误:invalid_scope
在网址列上手动改成+就没问题
请问这要怎麽改呢??
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.189.82
找到一个笨方法
把GET参数手动加
$url =
"
https://accounts.google.com/o/oauth2/auth?scope=".$scope."&".
http_build_query(array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'response_type' => 'code' ));
※ 编辑: onininon 来自: 220.133.189.82 (11/11 17:46)
1F:推 mervynW:urldecode 11/11 18:14
2F:推 showsky:我猜urlencode 问题http送进get 参数请先 urlencode 11/11 21:12
谢谢解答
$url =
"
https://accounts.google.com/o/oauth2/auth?".
http_build_query(array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'scope' => urldecode($scope),
'response_type' => 'code'
));
改成这样就没问题了!
※ 编辑: onininon 来自: 220.133.189.82 (11/14 11:27)