[英]Can't get access from my site to Google Drive API
I have a website that isn't allowed out of our network. 我有一个不允许访问我们网络的网站。 We use some domain name to access to it from our company's network (say
desire.it.loc
). 我们使用一些域名从我们公司的网络访问它(例如
desire.it.loc
)。 And now I need to upload some file to google drive from my site. 现在,我需要从我的网站上向Google驱动器上传一些文件。 As I got so far first I should do is to authenticate to google account.
到目前为止,我首先要做的是向Google帐户进行身份验证。 I created project at
google developers console
, got client_id, secret etc. And now I'm getting 我在
google developers console
创建了项目,得到了client_id,secret等。现在,我得到了
Error: invalid_request
device_id and device_name are required for private IP: http://x.x.x.x:x
My php code: 我的PHP代码:
session_start();
$client = new Google_Client();
$client->setApplicationName("limits");
$client->setDeveloperKey("<key goes here>");
$client->setClientId('<id goes here>');
$client->setClientSecret('<secret goes here>');
$client->setRedirectUri('http://x.x.x.x:x');
$client->setScopes(array('http://x.x.x.x:x'));
if ($_GET['logout'] == "1") {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl(); // error goes here
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
if (isset($_SESSION['token'])) {
print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Analytics($client);
$accounts = $service->management_accountSummaries->listManagementAccountSummaries();
foreach ($accounts->getItems() as $item) {
echo "Account: ",$item['name'], " " , $item['id'], "<br /> \n";
foreach($item->getWebProperties() as $wp) {
echo ' WebProperty: ' ,$wp['name'], " " , $wp['id'], "<br /> \n";
$views = $wp->getProfiles();
if (!is_null($views)) {
foreach($wp->getProfiles() as $view) {
// echo ' View: ' ,$view['name'], " " , $view['id'], "<br /> \n";
}
}
}
} // closes account summaries
}
print "<br><br><br>";
print "Access from google: " . $_SESSION['token'];
?>
I'm not the administrator of our web-server, so I guess it would be difficult for me to change some setting there. 我不是我们的网络服务器的管理员,因此我想很难在此更改某些设置。 Can I fix it somehow without registering "fake domains" or something like this.
我可以以某种方式解决此问题,而无需注册“假域名”或类似的东西。
$client->setRedirectUri(' http://xxxx:x '); $ client-> setRedirectUri(' http:// xxxx:x '); isn't allowed.
不允许。 You need a domain name such as dev.example.com.
您需要一个域名,例如dev.example.com。 You can configure your /etc/hosts (or windows equivalent) to resolve dev.example.com to the ip address.
您可以配置/ etc / hosts(或Windows等效)以将dev.example.com解析为IP地址。 The same domain name needs to be registered in the Google API Console.
必须在Google API控制台中注册相同的域名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.