我正在为应用程序使用Oauth 类来访问 Google 驱动器 API,我同时拥有刷新和访问令牌,现在我需要做的就是设置请求的参数。
我的问题是我似乎找不到获得适当响应所需的参数,我查看了 OAuth 游乐场,发送的请求有三个标头Authorization
, Host
并且Content length
.
我正在使用的类应该正确处理这些标头,并且我很确定它正在做正确的事情,因为它实际上正确地接收了code
and access/refresh tokens
。
当我发送请求时,Google 会返回一个错误;
StdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => authError
[message] => Invalid Credentials
[locationType] => header
[location] => Authorization
)
)
[code] => 401
[message] => Invalid Credentials
)
)
这肯定表明凭据无效?但如果我刚刚收到“新”访问令牌和刷新令牌,这肯定没问题吗?这是我发送的请求(根据 OAuth 类方法)。
$row = $this->docs_auth->row();
$this->client = new oauth_client_class;
$this->client->server = 'Google';
$this->client->redirect_uri = 'https://localhost/p4a/applications/reflex_application/index.php';
$this->client->debug = true;
$this->client->client_id = REFLEX_GOOGLE_CLIENT;
$this->client->client_secret = REFLEX_GOOGLE_SECRET;
$this->client->access_token = $row['access_token'];
$this->client->refresh_token = $row['refresh_token'];
$url = 'https://www.googleapis.com/drive/v2/files';
$Values = array(
'access_token' => $this->client->access_token,
'client_id' => $this->client->client_id,
'client_secret' => $this->client->client_secret
);
/*
* Request: GET https://www.googleapis.com/drive/v2/files
* $values = the values sent in the request
* $folder = the response returned from Google.
*/
$this->client->callAPI($url, 'GET', $values, array(
'FailOnAccessError' => false
), $folder);
$this->field->setValue(print_r($folder, true));
所以我的问题是,要发送给 Google 以获取文件夹和文件列表的正确参数是什么,以及请求所需的标头是什么(我不想过多地编辑类,但已经需要)。
谢谢你的时间