首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google predicate API刷新令牌异常

google predicate API刷新令牌异常
EN

Stack Overflow用户
提问于 2013-04-18 19:23:00
回答 1查看 227关注 0票数 0

我必须为一个项目使用Google Predicate API,所以我首先播放"Hello Predicate“示例https://developers.google.com/prediction/docs/hello_world

我想使用Service account auth方法直接从我的web服务器调用API

这是我的脚本,我总是得到一个

代码语言:javascript
复制
Google_AuthException Object
(
    [message:protected] => Error refreshing the OAuth2 token, message: '{
  "error" : "invalid_grant"
}

有什么建议吗?

代码语言:javascript
复制
            <?php
            ini_set('display_errors',1);
            error_reporting(E_ALL);

            require_once 'google-api-php-client/Google_Client.php';
            require_once 'google-api-php-client/contrib/Google_PredictionService.php';

            session_start();

            $client = new Google_Client();

            define("CLIENT_ID", 'xxxxxxxxxxxxxx.apps.googleusercontent.com');
            define("SERVICE_ACCOUNT_NAME", 'Prediction API Project');
            define("KEY_FILE", 'google-api-php-client/xxxxxxxxcd-privatekey.p12');

            $client = new Google_Client();
            $key = file_get_contents(KEY_FILE);


            $client->setAssertionCredentials(new Google_AssertionCredentials(
                                        SERVICE_ACCOUNT_NAME,
                                        array('https://www.googleapis.com/auth/devstorage.full_control'),
                                        $key));

            $client->setClientId(CLIENT_ID);

            $predictionService = new Google_PredictionService($client);
            $trainedmodels = $predictionService->trainedmodels;


                $id = "languageidentifier";
                $predictionText = "Je suis vraiment très très fatigué";
                $predictionData = new Google_InputInput();
               $predictionData->setCsvInstance(array($predictionText));
                $input = new Google_Input();
                 $input->setInput($predictionData);
                try{
                $result = $predictionService->trainedmodels->predict($id, $input);
                print("<h2>Prediction Result:</h2>");
                print_r($result);
                }

                catch (Exception $e)
                {
                    echo '<pre>';
                    print_r($e);
                    echo '</pre>';
                }
            ?>
EN

回答 1

Stack Overflow用户

发布于 2013-04-18 21:00:41

看起来我错过了望远镜里的预测

代码语言:javascript
复制
$client->setAssertionCredentials(new Google_AssertionCredentials(
                        EMAIL_ADDRESS,
                        array('https://www.googleapis.com/auth/devstorage.full_control','https://www.googleapis.com/auth/prediction'),
                        $key));

现在好了。

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

https://stackoverflow.com/questions/16081599

复制
相关文章

相似问题

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