Google PHP网站管理员API,权限错误

Google PHP网站管理员API,权限错误,php,google-api,google-api-php-client,google-api-webmasters,Php,Google Api,Google Api Php Client,Google Api Webmasters,我正在尝试实现谷歌新的网站管理员PHP API。 我已经在使用Google Analytics的连接器,在那里一切正常 我启用了API,gmail用户也是该站点的所有者。gmail用户还创建了客户端ID和服务帐户 然后我为我的服务帐户添加了两个网站管理员范围。 -->为此,我将我的服务帐户电子邮件从 946@developer.gserviceaccount.com =>946.apps.googleusercontent.com 并通过管理菜单添加了作用域 --我可能做错了什么 我想

我正在尝试实现谷歌新的网站管理员PHP API。 我已经在使用Google Analytics的连接器,在那里一切正常

我启用了API,gmail用户也是该站点的所有者。gmail用户还创建了客户端ID和服务帐户

然后我为我的服务帐户添加了两个网站管理员范围。 -->为此,我将我的服务帐户电子邮件从

 946@developer.gserviceaccount.com =>946.apps.googleusercontent.com
并通过管理菜单添加了作用域

--我可能做错了什么

我想我忘了添加或设置一些权限,但我真的不知道是哪一个。有人能帮上忙吗

我的错误是

Uncaught exception 'Google_Service_Exception' with message 'Error calling POST 
https://www.googleapis.com/webmasters/v3/sites/SITEURL/searchAnalytics/query: (403) 
User does not have sufficient permission for site 'SITEURL'.
 See also: https://support.google.com/webmasters/answer/2451999.'  
in E:\xampp\htdocs\google\google-api-php-client\src\Google\Http\REST.php:110 Stack trace: 
#0 E:\xampp\htdocs\google\google-api-php-client\src\Google\Http\REST.php(62):
 Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) 
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) 
#2 E:\xampp\htdocs\google\google-api-php-client\src\Google\Task\Runner.php(174): call_user_func_array(Array, Array) 
#3 E:\xampp\htdocs\google\google-api-php-client\src\Google\Http\REST.php(46): Google_Task_Runner->run() 
#4 E:\xampp\htdocs\google\google-api-php-client\src\Google\Client.php(593): 
Google_Http_REST::execute(Object(Google_Cl in E:\xampp\htdocs\google\google-api-php-client\src\Google\Http\REST.php on line 110
我的客户:

public function connect() {

        $this->setProfileId($this->options['ga_profile_id']);
        $this->client = new Google_Client();
        $this->client->setApplicationName("XXXNAMEXXX");
        $this->client->setClientId('XXXX946.apps.googleusercontent.com');
        $this->service = new Google_Service_Webmasters($this->client);

        if (isset($this->serviceToken)) {
            $this->client->setAccessToken($this->serviceToken);
        }
        $key = file_get_contents($this->options['ga_key_location']);

        $cred = new Google_Auth_AssertionCredentials(
            $this->options['ga_service_account_name'], array('https://www.googleapis.com/auth/webmasters.readonly','https://www.googleapis.com/auth/webmasters'), $key
        );

        $this->client->setAssertionCredentials($cred);

        if ($this->client->getAuth()->isAccessTokenExpired()) {
            $this->client->getAuth()->refreshTokenWithAssertion($cred);
        }

        $this->serviceToken = $this->client->getAccessToken();
    }
我的查询电话:

public function get_searchanalytics( $url, $limit = false, $dimensions = array( 'query' ), $aggregation_type = 'auto', $options = array() ) {
    $search = new Google_Service_Webmasters_SearchAnalyticsQueryRequest;
    $search->setStartDate( $start ? $start : date( 'Y-m-d', strtotime( '1 month ago' ) ) );
    $search->setEndDate( $end ? $end : date( 'Y-m-d', strtotime( 'now' ) ) );
    $search->setDimensions( $dimensions );
    if ( $limit ) $search->setRowLimit( $limit );
    $search->setAggregationType( $aggregation_type );
    return $this->service->searchanalytics->query( $url, $search, $options )->getRows();
}

你用过这个吗?我也有一个问题,让GWT网站管理员工具的工作。你说我启用了API。你是怎么做到的?它叫什么?因为当我去的时候,我没有看到任何类似GWT的东西。是的,回答你tommorow@MSchenkel在控制台中称为Google搜索控制台API