首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >想让Google accessToken

想让Google accessToken
EN

Stack Overflow用户
提问于 2014-11-17 04:00:04
回答 1查看 1.1K关注 0票数 0

看起来,不管我做什么,谷歌都在尽力阻止我完成这个研究项目。我的项目让我使用Google电子表格作为数据库,并使用上述电子表格中的数据执行编程的Google图片搜索,并向最终用户显示几个结果。

安装指令

我从这里的说明开始:https://github.com/asimlqt/php-google-spreadsheet-client。我将作曲家下载到我的计算机上,然后按照这里这里的说明让Composer下载必要的库到我的项目中。

编码过程之后,我试图复制这家伙在他的答案中所做的事情。实际上,这是我的代码:

代码语言:javascript
复制
<?php
    require "vendor/autoload.php";
    //require '/php-google-spreadsheet-client-master\src\Google\Spreadsheet\Autoloader.php';

    use Google\Spreadsheet\DefaultServiceRequest;
    use Google\Spreadsheet\ServiceRequestFactory;

    const GOOGLE_CLIENT_ID = 'someClientID'; // here, I just pulled the default client ID from my Google Developers account
    const GOOGLE_CLIENT_EMAIL = 'someClientEmail'; // I used the default client email here as well, again, straight from Google Developers account
    const GOOGLE_CLIENT_KEY = 'someKey'; // I used the key that I used for the Google Custom Search Engine 
    const GOOGLE_CLIENT_KEY_PATH = 'vendor\google\apiclient\examples\key.p12'; // I did a search on my project folder for the .p12 file that had the key information, and used that path here
    const G_CLIENT_KEY_PW   = 'notasecret'; // the default (I don't know why I need to do this)

    // setup the googleClient
    $googleClient = new Google_Client();
    $googleClient->setApplicationName('future-graph-611');
    $googleClient->setClientId(GOOGLE_CLIENT_ID);
    $googleClient->setAssertionCredentials(new Google_Auth_AssertionCredentials(
        GOOGLE_CLIENT_EMAIL,
        array('https://spreadsheets.google.com/feeds','https://docs.google.com/feeds'), 
        file_get_contents(GOOGLE_CLIENT_KEY_PATH),  // Why can't I use the hard-coded GOOGLE_CLIENT_KEY here?
        G_CLIENT_KEY_PW
    ));
    //$googleClient->setAccessType('offline');
    // get an accessToken
    try
    {
        $googleClient->getAuth()->refreshTokenWithAssertion();  // the problem is here, on this line
    }
    catch (Google_Auth_Exception $exception)
    {
        echo $exception->getMessage();
    }
    $accessToken = json_decode($googleClient->getAccessToken());
    $accessToken = $accessToken->access_token;
?>

出于某种原因,try块中的语句正在抛出异常: Error刷新OAuth2令牌,消息:'{ "invalid_grant“}‘。

我到底做错什么了?我还需要做些什么,这样才能起作用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-18 22:43:53

我想我在这里找到了答案:https://github.com/asimlqt/php-google-spreadsheet-client/issues/24

/*由于某些原因,在行CURLOPT_SSL_VERIFYPEER => true上遇到了问题(并通过将索引设置为false来修正) */

还有,echo $SpencerWieczorek->getResponse($this->getQuestion());

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26965299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档