How Can I Connect to Google Ads Account Using Google Login with PHP?

197 views
Skip to first unread message

ma...@sumer.me

unread,
Jul 4, 2020, 3:20:38 AM7/4/20
to AdWords API and Google Ads API Forum
I have an Google Ads API Account. And I want to login to customers account with google login and check account using API. How can i connect? Is there any documentation or PHP sample code?

Google Ads API Forum Advisor Prod

unread,
Jul 6, 2020, 3:01:34 PM7/6/20
to ma...@sumer.me, adwor...@googlegroups.com
Hello,

Thank you for reaching out. To connect to the API and make your first request, you can follow our Quickstart Guide. We have a PHP client library available here where you can find sample code as well. Let me know if you have any additional questions while trying to set up your API connection.

Regards,
Danica, Google Ads API Team

ref:_00D1U1174p._5004Q21j8f3:ref

ma...@sumer.me

unread,
Jul 7, 2020, 5:48:07 AM7/7/20
to AdWords API and Google Ads API Forum
First of all, thank you for the help. But I guess I couldn't express it fully.

I am currently using the Google Ads API, there is no problem. I want to connect to another client's Ads account and manage their campaigns. I want to use Google Login for this.

So the customer will click on a link that I will give and say Google Login and I will be able to access his account. Like Wordstream login system. (https://app.wordstream.com/login)

6 Temmuz 2020 Pazartesi tarihinde saat 21:01:34 UTC+2 itibarıyla adsapiforumadvisor şunları yazdı:

Google Ads API Forum Advisor Prod

unread,
Jul 7, 2020, 3:52:43 PM7/7/20
to ma...@sumer.me, adwor...@googlegroups.com
Hello,

Thank you for clarifying! It does not look like this is possible for Google Ads API. I have raised a feature request on your behalf. If the team decides this is a viable request, you can find updates on our blog if it is available in future releases.

Let me know if you have any additional questions.

ma...@sumer.me

unread,
Jul 7, 2020, 4:23:55 PM7/7/20
to AdWords API and Google Ads API Forum
Are you sure this is not possible? Because Wordstream actually does this job. When you log in to them with your Google Ads account, they can manage your campaigns.

Actually, I succeeded partially in the link below, but for some reason I cannot get access to the account. Where is my fault I'm trying to figure it out.


Code: 

require 'google-api/vendor/autoload.php';
use Google\Auth\OAuth2;
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\CampaignService;
use Google\AdsApi\Common\OAuth2TokenBuilder;

session_start();
$oauth2 = new OAuth2([
   'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
   'redirectUri' => 'XXXXX',
   'clientId' => 'XXXXXX,
   'clientSecret' => 'XXXXX',
   'refresh_token' => XXXXX'
]);
if(!isset($_GET['code'])){
$oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
$_SESSION['oauth2state'] = $oauth2->getState();
$config = [
   
       'access_type' => 'offline',
       'prompt' => 'consent',
];
header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
exit;
 
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])){
 
  unset($_SESSION['oauth2state']);
  exit('Invalid state.');
 
} else {
$oauth2->setCode($_GET['code']);
$authToken = $oauth2->fetchAuthToken();
$refreshToken = $authToken['refresh_token'];
$path = "xxxxxx/google-api/vendor/adsapi_php.ini";
$session = (new AdWordsSessionBuilder())
   ->fromFile($path)
   ->withOAuth2Credential($oauth2)
   ->build();
$adWordsServices = new AdWordsServices();
$campaignService = $adWordsServices->get($session, CampaignService::class);
print_r($campaignService);
}

7 Temmuz 2020 Salı tarihinde saat 21:52:43 UTC+2 itibarıyla adsapiforumadvisor şunları yazdı:

Google Ads API Forum Advisor Prod

unread,
Jul 8, 2020, 10:37:55 AM7/8/20
to ma...@sumer.me, adwor...@googlegroups.com
Hello,

I can see that you are using AdWords API in your code to make calls to CampaignService. Can you please provide the complete detailed logs of the request and response so that I can take a look at the errors you are receiving? You can enable logging by following this guide. Since you mentioned not being able to access the account, can you also provide the customerClientId along with the email you used to authenticate the API call? Please ensure you "Reply privately to author" when providing this information.

ma...@sumer.me

unread,
Jul 17, 2020, 4:38:42 AM7/17/20
to AdWords API and Google Ads API Forum
Firstly i can't click to "Reply privately to author" button. This button is disabled.

And actually my main problem is not about Google AdWords or Google Ads. My first problem is i can't access to any customers account with Google Login. How can i do this with PHP? If you click to this link, you can see what i mean.


8 Temmuz 2020 Çarşamba tarihinde saat 16:37:55 UTC+2 itibarıyla adsapiforumadvisor şunları yazdı:

Google Ads API Forum Advisor Prod

unread,
Jul 17, 2020, 12:26:40 PM7/17/20
to ma...@sumer.me, adwor...@googlegroups.com
Hello,

You mentioned that you can't access any customer's account with Google Login. Can you confirm the following:
  • If the customers you are referring to are Google Ads customer client accounts. If so, do you have access to these customers in general (i.e. you can access their accounts via the Google Ads UI)? If you can provide your CID as well as the CIDs you are trying to access, this may help as well.
  • If you are receiving any Google Ads/AdWords API errors in your implementation with Google Login
  • If you are trying to use Google Identity Platform to integrate Google Sign-In as your "Google Login." If not, what are you using to implement this?
Please note that our team can only provide support for Google Ads API or AdWords API. If you are not receiving any error messages from the Google Ads/AdWords API, this issue may be out of scope for our team.
Reply all
Reply to author
Forward
0 new messages