如何使用 google 广告 api 代表您的客户访问
How to use google ads api access on behalf your client
我是 google 广告库中的新人,我遇到了问题
我将 google adswords api 库添加到新的 laravel 5.3 中。
我使用 ini 文件拨打电话并检索数据,但是当我尝试代表您的客户使用访问权限时
this wiki of the library
但是我不明白的最后一部分不起作用
4. You can now use the OAuth2 object to make calls using the client library.
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oauth2)
->build();
$adWordsServices = new AdWordsServices();
$campaignService =
$adWordsServices->get($session, 'CampaignService', 'v201603', 'cm');
// Make calls using $campaignService.
当我尝试示例中的代码时,他们给出了错误 Undefined variable: oauth2
我尝试将它从会话中的连接文件中放入并在示例文件中检索它,但没有成功
还有一个问题:
我代表您的客户将 ClientCustomerId 放在哪里??
谢谢
首先,你少了一小步。您需要 OAuth2 实例,如教程中所示,
session_start();
$oauth2 = new OAuth2([
'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
'redirectUri' => '****',
'clientId' => '****',
'clientSecret' => '****',
'scope' => '****'
]);
ClientCustomerId 应放在 adsapi_php.ini 文件中,您可以在 Github.
上找到该文件
一段时间后,我找到了问题的答案:
首先:
when i try the code in the examples they given it give me error Undefined variable: oauth2
i try to put it from the connection file in session and retrieve it in
the example file but not worked
这个问题的答案在 wiki 中,他们将代码放在一个文件中。所以如果你想把代码工作放在一个文件中。如果你想把它放在其他文件中或将一个 oauth2 用于多个文件,你只需要传递它
通过路由请求
或通过中间件
(laravel 5.* $request->attributes->add(['the_name_you_want' => $client]);
您可以通过此代码检索它 $client = \Request::get('the_name_you_want')
)
第二个问题:
where i put the ClientCustomerId in on behalf of your client ??
这很容易找到,只需像这样将它放在选择器部分
$session = (new AdWordsSessionBuilder())
->fromFile()
->withClientCustomerId('xxx-xxx-xxxx') //change it to what you want
->withOAuth2Credential($client)
->build();
这是我的最后一个问题
感谢您帮助尝试的人 ;)
我是 google 广告库中的新人,我遇到了问题
我将 google adswords api 库添加到新的 laravel 5.3 中。
我使用 ini 文件拨打电话并检索数据,但是当我尝试代表您的客户使用访问权限时 this wiki of the library
但是我不明白的最后一部分不起作用
4. You can now use the OAuth2 object to make calls using the client library.
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oauth2)
->build();
$adWordsServices = new AdWordsServices();
$campaignService =
$adWordsServices->get($session, 'CampaignService', 'v201603', 'cm');
// Make calls using $campaignService.
当我尝试示例中的代码时,他们给出了错误 Undefined variable: oauth2
我尝试将它从会话中的连接文件中放入并在示例文件中检索它,但没有成功
还有一个问题:
我代表您的客户将 ClientCustomerId 放在哪里??
谢谢
首先,你少了一小步。您需要 OAuth2 实例,如教程中所示,
session_start();
$oauth2 = new OAuth2([
'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
'redirectUri' => '****',
'clientId' => '****',
'clientSecret' => '****',
'scope' => '****'
]);
ClientCustomerId 应放在 adsapi_php.ini 文件中,您可以在 Github.
上找到该文件一段时间后,我找到了问题的答案:
首先:
when i try the code in the examples they given it give me error Undefined variable: oauth2
i try to put it from the connection file in session and retrieve it in the example file but not worked
这个问题的答案在 wiki 中,他们将代码放在一个文件中。所以如果你想把代码工作放在一个文件中。如果你想把它放在其他文件中或将一个 oauth2 用于多个文件,你只需要传递它
通过路由请求
或通过中间件
(laravel 5.* $request->attributes->add(['the_name_you_want' => $client]);
您可以通过此代码检索它 $client = \Request::get('the_name_you_want')
)
第二个问题:
where i put the ClientCustomerId in on behalf of your client ??
这很容易找到,只需像这样将它放在选择器部分
$session = (new AdWordsSessionBuilder())
->fromFile()
->withClientCustomerId('xxx-xxx-xxxx') //change it to what you want
->withOAuth2Credential($client)
->build();
这是我的最后一个问题
感谢您帮助尝试的人 ;)