【发布时间】:2018-01-29 16:00:53
【问题描述】:
我最近开发了一个允许用户通过谷歌登录的应用程序。我刚刚注意到(在测试中)谷歌不允许在设备 web 视图中访问 OAuth。
我目前的google登录代码如下
$client = new \Google_Client();
$url = 'myurl';
$client->setAuthConfigFile('../myconfigfile.com.json');
$client->setRedirectUri($url);
$client->addScope(\Google_Service_Drive::DRIVE_METADATA_READONLY);
if (!isset($_GET['code'])) {
/* Google App Client Id */
define('CLIENT_ID', 'myid');
/* Google App Client Secret */
define('CLIENT_SECRET', 'mysecret');
/* Google App Redirect Url */
define('CLIENT_REDIRECT_URL', $url);
$googleURL = 'https://accounts.google.com/o/oauth2/v2/auth?scope=' . urlencode('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me') . '&redirect_uri=' . urlencode(CLIENT_REDIRECT_URL) . '&response_type=code&client_id=' . CLIENT_ID . '&access_type=online';
header("Location: " .$googleURL);
exit();
}
此代码在浏览器上运行良好,但是当我在设备上运行它(目前在 iPad 上测试)时,它会出错并抛出“不允许的用户代理”问题。
我如何获得它以便它加载到浏览器应用程序中,而不是 web 视图中,或者如果这不可行,是否有使用 php 的解决方法?
【问题讨论】:
标签: php webview user-agent google-oauth