Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
PHP页面没有';在从Google获得oAuth响应以访问API后加载_Php_Api_Google Analytics_Google Api Php Client - Fatal编程技术网

PHP页面没有';在从Google获得oAuth响应以访问API后加载

PHP页面没有';在从Google获得oAuth响应以访问API后加载,php,api,google-analytics,google-api-php-client,Php,Api,Google Analytics,Google Api Php Client,尝试通过快速入门指南通过PHP()使Google Analytics API正常工作。当页面加载并跳转到Google进行授权时,从Google返回的回调页面将不会加载:oauth2callback.php?code=4/XVILRDCNPY6MPFD6MCQE2oownIniodiZCC0IYX8ZTNTM 我只是从Chrome获得以下信息,没有PHP错误或任何东西: 没有收到任何数据 错误\u空\u响应 oauth2callback.php: <?php require_once 'go

尝试通过快速入门指南通过PHP()使Google Analytics API正常工作。当页面加载并跳转到Google进行授权时,从Google返回的回调页面将不会加载:
oauth2callback.php?code=4/XVILRDCNPY6MPFD6MCQE2oownIniodiZCC0IYX8ZTNTM

我只是从Chrome获得以下信息,没有PHP错误或任何东西:

没有收到任何数据 错误\u空\u响应

oauth2callback.php:

<?php
require_once 'google-api-php-client/src/Google/autoload.php';

// Start a session to persist credentials.
session_start();

// Create the client object and set the authorization configuration
// from the client_secrets.json you downloaded from the Developers Console.
$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.json');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/jeremy/oauth2callback.php');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);

// Handle authorization flow from the server.
if (! isset($_GET['code'])) {
  $auth_url = $client->createAuthUrl();
  header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/jeremy/';
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

我在您的实现中看到的唯一区别是url中有一个额外的级别“/jeremy/”。您是否在开发人员控制台中拥有重定向url的完整路径,并将index.php设置为http://{yourhostname}/jeremy/oauth2callback。php@Matt是的,它是用开发者控制台和index.php文件中的子文件夹设置的。我在实现中看到的唯一区别是url中有一个额外的级别“/jeremy/”。您是否在开发人员控制台中拥有重定向url的完整路径,并将index.php设置为http://{yourhostname}/jeremy/oauth2callback。php@Matt是的,它是使用开发者控制台和index.php文件中的子文件夹设置的。