YouTube Analytics API PHP:usageLimits accessNotConfigured

时间:2014-12-23 15:08:23

标签: php youtube youtube-api youtube-analytics

我通过wanze使用[Google AnalyticsAPI PHP]。我能够设置身份验证(仅使用Web身份验证)和所有内容,并将令牌存储在会话中。在另一个页面上,我使用此代码查找用户登录的所有帐户。

session_start();
include('GoogleAnalyticsAPI.class.php');

$ga = new GoogleAnalyticsAPI(); 
$ga->auth->setClientId('replaces'); // From the APIs console
$ga->auth->setClientSecret('replaces'); // From the APIs console
$ga->auth->setRedirectUri('replaced'); // Url to your app, must match one in the APIs console

// Get the Auth-Url
$url = $ga->auth->buildAuthUrl();

// Set the accessToken and Account-Id
$ga->setAccessToken($_SESSION['accessToken']);
$ga->setAccountId('ga:xxxxxxx');

// Load profiles
$profiles = $ga->getProfiles();
print_r($profiles);
$accounts = array();
foreach ($profiles['items'] as $item) {
    $id = "ga:{$item['id']}";
    $name = $item['name'];
    $accounts[$id] = $name;
}
// Print out the Accounts with Id => Name. Save the Id (array-key) of the account you want to query data. 
// See next chapter how to set the account-id.
print_r($accounts); 

我回来了:

Array
(
    [http_code] => 403
    [error] => Array
        (
            [errors] => Array
                (
                    [0] => Array
                        (
                            [domain] => usageLimits
                            [reason] => accessNotConfigured
                            [message] => Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.
                            [extendedHelp] => https://console.developers.google.com
                        )

                )

            [code] => 403
            [message] => Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.
        )

)
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home3/chalzzy/public_html/dashboard/dashboard.php</b> on line <b>21</b><br />
Array
(
)

我在很多地方看到我需要删除或设置所有引用在控制台的“引用”部分,但我似乎无法在新的或旧的控制台中鳍。如果它在那里,我找不到它,你能给我一个网址或截图吗?

此外,这些是我为此项目安装的所有API:

List of API

提前致谢,

另外,如果您需要更多详细信息,请与我们联系!

1 个答案:

答案 0 :(得分:2)

嘿(对不起,这是一个非常愚蠢的问题),

您需要做的是添加到您的API列表&#34; Analytics API&#34;在Developers Console