1

尝试连接 AdSense 管理 API 示例时出现以下错误:

缺少必需参数:redirect_uri

我正在使用服务帐户,因为我的服务器处理 adSense api 之间的所有交互。用户不参与。这是我的 PHP 代码:

$client = new Google_Client();
$client->setApplicationName("PeopleHelpingPeople"); // name of your app

// set assertion credentials
$client->setAssertionCredentials(
  new Google_Auth_AssertionCredentials(
    "...", 
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents('client_data.json')  // keyfile you downloaded
));
$client->setScopes(array(
'https://www.googleapis.com/auth/analytics.readonly'
));
$client->setClientId("...");           // from API console
$client->setAccessType('offline_access');  // this may be unnecessary?

// Create service.
$service = new Google_Service_AdSense($client);

为什么我会收到此错误?

4

1 回答 1

1

如果您尝试使用开发人员控制台中的 ServiceAccount,即为您提供 p12 文件的帐户,则这些帐户不适用于 Adsense。

看看这个页面上的注释https://developers.google.com/adsense/management/getting_started

$client->setRedirectUri() 可能会让你克服这个错误,但它不会解决你的最终问题

于 2015-05-06T20:42:10.457 回答