Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在google日历API中将凭证或令牌从JS传递到PHP_Javascript_Php_Google Calendar Api - Fatal编程技术网

Javascript 在google日历API中将凭证或令牌从JS传递到PHP

Javascript 在google日历API中将凭证或令牌从JS传递到PHP,javascript,php,google-calendar-api,Javascript,Php,Google Calendar Api,我甚至不确定这是否可能。我正在尝试将事件添加到google日历中。通过Javascript的授权正在运行。我能够从用户处获得授权。用户将在填写表单时登录,然后提交表单以在服务器中进行处理。我需要在表单提交后插入事件。这是因为在处理表单之前有许多验证。我想知道是否有可能传递访问令牌或一些验证,以便使用google api在服务器端添加事件。所以用户使用JS登录,但事件是用PHP插入的。这就是我目前所拥有的 token = gapi.auth2.getAuthInstance().currentUs

我甚至不确定这是否可能。我正在尝试将事件添加到google日历中。通过Javascript的授权正在运行。我能够从用户处获得授权。用户将在填写表单时登录,然后提交表单以在服务器中进行处理。我需要在表单提交后插入事件。这是因为在处理表单之前有许多验证。我想知道是否有可能传递访问令牌或一些验证,以便使用google api在服务器端添加事件。所以用户使用JS登录,但事件是用PHP插入的。这就是我目前所拥有的

token = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().access_token;
///user is logged in and I can get access token
$.ajax({

    url : 'aa_calendar.php',
    type : 'post',
    data : 'token='+token,
    dataType:'json',
    success : function(result) {              
        console.log(result);
        $("#content").html(result.msg);
    }
});
现在在aa_calendar.php中

$client = new Google_Client();
$client->setApplicationName('Remote Sessions');


$client->setClientId('xxxxxxxxxxxxxxxxxxxx');
$client->setClientSecret('xxxxxxxxxxxxxxxxxx');
$client->setDeveloperKey('xxxxxxxxxxxxxxxxxxxxxx');
$client->setScopes(array('https://www.googleapis.com/auth/calendar'));
$client->setAccessToken($_POST['token']);
这就是我得到的错误 未捕获的Google_Auth_异常:无法对令牌进行json解码 我想这并不像传递一个令牌那么简单:/


谢谢大家的帮助

您是否可以选择使用服务帐户在PHP中创建事件?我必须这样做。