简体   繁体   English

Google Analytics PHP API重定向URI

[英]Google Analytics PHP API Redirect URI

I'm testing the Google Analytics API (with oauth 2.0) on my local machine and I want to know if it's possible to get it to work this way as they request me to insert a Redirect URI in the Google APIs Console and then enter it in my code but I do not know what this Redirect URI should be? 我正在我的本地计算机上测试Google Analytics(分析)API(使用oauth 2.0),我想知道是否有可能以这种方式工作,因为他们要求我在Google API控制台中插入重定向URI,然后输入在我的代码中,但我不知道此重定向URI应该是什么?

My current Redirect URI is https://localhost/oauth2callback and I tried https://gapi.local/oauth2callback but neither works for me. 我当前的重定向URI是https://localhost/oauth2callback ,我尝试了https://gapi.local/oauth2callback但均不适用于我。

I get this error message: 我收到此错误消息:
Fatal error: Call to undefined method apiClient::setClientRedirectUri() in C:\\xampp\\htdocs\\webs\\gapi\\HelloAnalyticsApi.php on line 15

Any help would be appreciated. 任何帮助,将不胜感激。

The google-api-php-client library has no method setClientRedirectUri() in apiClient . google-api-php-client库apiClient没有方法setClientRedirectUri() The correct method is called setRedirectUri() : 正确的方法称为setRedirectUri()

$client = new apiClient();
$client->setApplicationName('Hello Analytics API Sample');

// Visit //code.google.com/apis/console?api=analytics to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$client->setDeveloperKey('insert_your_developer_key');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM