【发布时间】:2019-02-13 02:35:11
【问题描述】:
我第一次使用谷歌 api 我的代码执行完美,甚至使用人员服务 api 给我数据...但第二次它给我以下错误
类型:Google_Service_Exception
Message: { "error": { "code": 403, "message": "请求丢失 一个有效的 API 密钥。", "errors": [ { "message": "请求缺少一个 有效的 API 密钥。”、“域”:“全局”、“原因”:“禁止”}]、 “状态”:“PERMISSION_DENIED”} }
我正在使用 codeignitor,这是重定向的 uri 控制器功能...在此先感谢,抱歉英语不好..
$client = $this->google_client_setup();
$client->authenticate($this->input->get('code'));
$access_token = $client->getAccessToken();
$people_service = new Google_Service_PeopleService($client);
$profile = $people_service->people->get(
'people/me', array('personFields' => 'names,emailAddresses'));
$access_token = $access_token['access_token'];
$email = $profile['emailAddresses'][0]['value'];
$name = $profile['names'][0]['displayName'];
$user = [
'email' => $email,
'name' => $name,
'is_admin' => 0
];
【问题讨论】:
-
如果没有看到控制器的其余部分并知道它是如何被调用的,很难判断,但很可能在第二次运行时您没有通过
GET获得code。这将导致$client无法正确设置,然后使用它的所有东西都会开始表现异常 -
但我的代码第一次完美执行..刷新页面时出现此错误
-
这正是我的意思...看来在第一次运行时您通过
GET正确传递了变量,但刷新页面时却没有
标签: php codeigniter google-api