如何使用JSON密钥数据在php中请求访问令牌?

时间:2019-09-15 04:59:18

标签: php google-analytics credentials

我正在尝试将Google Analytics(分析)嵌入库与PHP API https://github.com/googleapis/google-api-php-client结合使用。

在库页面本身https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/上有一个示例,但是该示例适用于python,我在PHP库中寻找了类似的函数,但未找到它。

简而言之,我需要使用PHP提供的JSON文件获取访问令牌。

谁能帮助我,我非常感激,我已经测试了3天的各种功能和库。

    function initializeAnalytics()
    {
        // Creates and returns the Analytics Reporting service object.

        // Use the developers console and download your service account
        // credentials in JSON format. Place them in this directory or
        // change the key file location if necessary.
        $KEY_FILE_LOCATION = __DIR__ . '/igneous-future-252421-929cebfbbc73.json';

        // Create and configure a new client object.
        $client = new Google_Client();
        $client->setApplicationName("Hello Analytics Reporting");
        $client->setAuthConfig($KEY_FILE_LOCATION);
        $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
        $analytics = new Google_Service_Analytics($client);

        return $analytics;
    }

PHP中的此功能正在运行,我需要实现它才能接收访问令牌。我尝试使用诸如getAuth,getAccessToken之类的方法,但无济于事。

0 个答案:

没有答案