php – 需要Google AnalyticsAPI登录错误
发布时间:2020-12-13 22:51:26 所属栏目:PHP教程 来源:网络整理
导读:我有一个奇怪的问题,我试图解决,但我已经尝试了一整天,它只是不起作用,所以我希望也许别人可以帮助我. 我已经构建了一个CMS,在您登录后,您会看到仪表板. 在此信息中心,您可以点击按钮将您的帐户与Google相关联 – 因为我希望我的客户能够连接其Google Analyt
我有一个奇怪的问题,我试图解决,但我已经尝试了一整天,它只是不起作用,所以我希望也许别人可以帮助我.
我已经构建了一个CMS,在您登录后,您会看到仪表板. 一切正常,我有令牌和刷新令牌,一切似乎都有效.即使我请求我的用户个人资料数据,我也会将其作为数组打印在我的屏幕上.但是当我尝试获取可供连接用户查看的帐户时,我收到此错误: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties key=xxxxxxxxxxxxxxxxxxxxxxxxxx: (401) Login Required' 我只是不明白为什么我收到“需要登录”的消息. require_once('/Google/Client.php'); require_once('/Google/Service/Analytics.php'); // call object $client = new Google_Client(); $client->setApplicationName("Google Analytics - CMS title"); $client->setClientId('xxxxxxxxxxxxxxxxx'); $client->setClientSecret('xxxxxxxxxxxxxxxx'); $client->setRedirectUri('xxxxxxxxxxxxxxxxxxx'); $client->setDeveloperKey('xxxxxxxxxxxxxxxxxxx'); $client->setApprovalPrompt('auto'); $client->setAccessType('offline'); $client->setScopes(array( 'https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/analytics' )); // decode $token = $token; // this comes from my database and it's json encoded // connect $client->setAccessToken($token); // call service $service = new Google_Service_Analytics($client); // get accounts from analytics $accounts = $service->management_accounts->listManagementAccounts(); 当我尝试var_dump $accounts时,我没有看到任何因为错误已经发生(需要登录) 我想你现在会问我,如果我的令牌是正确的,但这是因为我用其他api调用测试它…它只是不适用于这个特定的分析请求. 我希望有人可以帮助我. 谢谢, 更新: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management /accounts?key=xxxxxxxxxxxxxxxxxx: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project. 我启用了Google Analytics服务,但不知道我还需要启用哪个服务. 解决方法
401错误
clearly表明凭据错误.令牌可能对检索数据有效,但是为了检索用户管理信息,在请求该令牌时需要特定的授权,请在表格中查看
here,您会看到要在OAuth请求中设置的scope参数的附加值.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |