Json 键缺少类型字段 [英] Json key is missing the type field

查看:25
本文介绍了Json 键缺少类型字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 google api for php 2.2.0 版连接到我的 Google 日历.到目前为止,我无法成功连接到我的日历,这非常令人沮丧.

I try to connect to my Google calendar using the google api for php, version 2.2.0. Until now I do not succeed in connecting to my calendar and that is very frustrating.

此时我收到以下致命错误:

At this moment I recieve the following fatal error:

致命错误:未捕获的 InvalidArgumentException:缺少 json 密钥中的类型字段/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php:123 堆栈跟踪:#0/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/ApplicationDefaultCredentials.php(154):Google\Auth\CredentialsLoader::makeCredentials('https://www.goo...',数组)#1/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(1078):Google\Auth\ApplicationDefaultCredentials::getCredentials('https://www.goo...')

Fatal error: Uncaught InvalidArgumentException: json key is missing the type field in /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php:123 Stack trace: #0 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/ApplicationDefaultCredentials.php(154): Google\Auth\CredentialsLoader::makeCredentials('https://www.goo...', Array) #1 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(1078): Google\Auth\ApplicationDefaultCredentials::getCredentials('https://www.goo...')

Google_Client->createApplicationDefaultCredentials() #3/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(786):Google_Client->authorize() #4/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Service/Resource.php(232):谷歌_C/home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php在线 123

Google_Client->createApplicationDefaultCredentials() #3 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(786): Google_Client->authorize() #4 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Service/Resource.php(232): Google_C in /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php on line 123

我使用此代码:

require_once WP_PLUGIN_DIR . '/google-api-php-client-2.2.0/vendor/autoload.php';
require_once WP_PLUGIN_DIR . '/google-api-php-client-2.2.0/src/Google/Client.php';
require_once WP_PLUGIN_DIR . "/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/Calendar/Resource/CalendarList.php";
require_once WP_PLUGIN_DIR . "/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/Oauth2.php";


putenv('GOOGLE_APPLICATION_CREDENTIALS=' . dirname(__FILE__) . '/oauth-credentials.json');

$client = new Google_Client();
$redirect_uri = 'https://myredirect-uri';
$client->setRedirectUri($redirect_uri);

$client->setRedirectUri($redirect_uri);
$client->setClientId('myclient-di.apps.googleusercontent.com');
$client->setClientSecret('myclient-secret');
$client->setAccessType("offline");        // offline access
$client->setIncludeGrantedScopes(true);   // incremental auth
$client->addScope(Google_Service_Calendar::CALENDAR);

$user_to_impersonate = 'owner-of-agenda@gmail.com';
$client->setSubject($user_to_impersonate);
$client->setAuthConfig(GOOGLE_APPLICATION_CREDENTIALS);

$client->useApplicationDefaultCredentials();

if (file_exists(CREDENTIALS_PATH)) {
    $token = file_get_contents(CREDENTIALS_PATH);
    echo "<h4>_Token</h4>";
    var_dump($token);
    $client->setAccessToken($token);
}
echo "<br><br>CLIENT";

$service = new Google_Service_Calendar($client);

$calendarList = $service->calendarList->listCalendarList();
var_dump($calendarList);

echo "<h4>End of example</h4>";

我看到生成了一个令牌.

I see that an token is generated.

有人可以帮助我建立这种联系吗?

Could someone please assist me in making this connection?

推荐答案

我解决了,JSON-key-file 没有包含 type 字段.但是我删除了一些语句并返回到最少的数据.还添加了声明:

I solved it, The JSON-key-file did not contain the type field. But I removed some statements and went back to the minimum of data. Added also the statement:

$client->setApprovalPrompt('force');

这篇关于Json 键缺少类型字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆