Adwords PHP API Web Application problem

431 views
Skip to first unread message

robert...@convierta.cl

unread,
Jan 20, 2016, 2:22:09 PM1/20/16
to AdWords API Forum
Hi.

I want to create a Web application in php to manage the Adwords account in my digital agency.
I downloaded "The Google Ads API PHP Client Library" from https://github.com/googleads/googleads-php-lib.
I created a Web application and configured the application except the "refresh_token" parameter. According to the instructions, to get it, I have to run the GetRefreshToken.php script from the command line. I Run the script and the link that I got back is only good for "Installed application", but not for "Web Applications" (the same issue has been mentioned in Making first request problem - can not get refresh token. )

"The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob can only be used by a Client ID for native application. It is not allowed for the 'WEB' client type. You can create a Client ID for native application in the Credentials section of the Google Developers Console."

I also tried installing "Google APIs Client Library for PHP" (https://github.com/google/google-api-php-client/tree/v1-master), and it worked for services like Youtube or Drive:

    $client-> addScope ("https://www.googleapis.com/auth/drive");
    $client-> addScope ("https://www.googleapis.com/auth/youtube");
    $dr_service = new Google_Service_Drive($client);
    $dt_service = new Google_Service_Youtube($client);

But there is no "Google_Service_Adwords".

Moreover, in the "Google Developers Console" page, in the part where the available API for applications are selected, "Adwords" does not appear.

Using the "APIs Discovery Service v1" (https://developers.google.com/apis-explorer/#p/discovery/v1/discovery.apis.list), when I asked for Adwords, did not show any results.

After these tests, I concluded that perhaps there is no PHP AdWords API for web applications and would like to confirm with you whether it is possible or not and, if possible, what is the right way to do it.

Thanks for your assistance on this.

Roberto

Yin Niu

unread,
Jan 20, 2016, 2:49:10 PM1/20/16
to AdWords API Forum
Hi Roberto, 

You can still use the installed application type for you web application if you are using a single top level manager account to manage all of your AdWords account. 

If you would like to use web application type, please follow the Using OAuth 2.0 for Web Server Applications Guide. 
Thanks,
Yin, AdWords API Team. 

robert...@convierta.cl

unread,
Jan 20, 2016, 3:17:13 PM1/20/16
to AdWords API Forum
Hi Yin, thanks for your answer.

I had followed the link. In the example this line appears:

$drive_service = new Google_Service_Drive($client);

But there is no Google_Service_Adwords, so I can't use Adword API. If I put Google_Service_Adwords on the code, the script fails.

I've searched the forum and have not found anyone who has managed to use the APIs Adwors with auth2 in a Web App.

Any help is appreciated.

Roberto

Yin Niu

unread,
Jan 20, 2016, 3:32:25 PM1/20/16
to AdWords API Forum
Hi Roberto, 

The scope for adwords api is: https://www.googleapis.com/auth/adwords. 

robert...@convierta.cl

unread,
Jan 20, 2016, 3:41:02 PM1/20/16
to AdWords API Forum
Hi Yin.

I've set the scope this way:


But then I need to access the Adwords Service.

The youtube and drive examples use:

    $client->addScope("https://www.googleapis.com/auth/youtube");
    $client->addScope("https://www.googleapis.com/auth/drive");

And then, for the services:

    $yt_service = new Google_Service_YouTube($client);
    $dr_service = new Google_Service_Drive($client);

So I tried with:

    $aw_service = new Google_Service_Adwords($client);

And then php fails. I don't know if Adwords Service have another name...

Regards

robert...@convierta.cl

unread,
Jan 20, 2016, 4:16:27 PM1/20/16
to AdWords API Forum
Hello Yin.

The php examples have this include for the drive service:

require_once 'Google/Service/Drive.php';

So I searched the Google/Service/ folder list for somethig like Adwords but didn't found it. This is the file list of services:

AdExchangeBuyer.php
AdExchangeSeller.php
Admin.php
AdSenseHost.php
AdSense.php
Analytics.php
AndroidPublisher.php
Appsactivity.php
AppState.php
Audit.php
Autoscaler.php
Bigquery.php
Blogger.php
Books.php
Calendar.php
CivicInfo.php
CloudMonitoring.php
Compute.php
Coordinate.php
Customsearch.php
Datastore.php
Dfareporting.php
Directory.php
Dns.php
DoubleClickBidManager.php
Doubleclicksearch.php
Drive.php
Exception.php
Freebase.php
Fusiontables.php
GamesManagement.php
Games.php
Genomics.php
Gmail.php
GroupsMigration.php
Groupssettings.php
IdentityToolkit.php
Licensing.php
Manager.php
MapsEngine.php
Mirror.php
Oauth2.php
Orkut.php
Pagespeedonline.php
PlusDomains.php
Plus.php
Prediction.php
Pubsub.php
QPXExpress.php
Replicapool.php
Reports.php
Reseller.php
Resource.php
Resourceviews.php
ShoppingContent.php
SiteVerification.php
Spectrum.php
SQLAdmin.php
Storage.php
Taskqueue.php
Tasks.php
Translate.php
Urlshortener.php
Webfonts.php
Webmasters.php
YouTubeAnalytics.php
YouTube.php

Please tell me if I'm doing something wrong.

Best regards

Thanet Knack Praneenararat (AdWords API Team)

unread,
Jan 21, 2016, 8:54:29 AM1/21/16
to AdWords API Forum
Hi Roberto,

As Yin has suggested, you can use installed application type for your web application.
Do you consider this option too? Do you have a strong business need to use web application type?

As for getting refresh tokens, you can do it via OAuth2 Playground too.

Best, 
Thanet, AdWords API Team

robert...@convierta.cl

unread,
Jan 21, 2016, 11:24:12 AM1/21/16
to AdWords API Forum
Hello Thanet, thanks for your answer.

I tried it via OAuth2 Playground and it works. I didn't read well that I can use installed application type for your web application. I don't know which is the best option, but at if I'll have problems with the web app I will use an installed one.

Thanks again and best regards
Roberto

Thanet Knack Praneenararat (AdWords API Team)

unread,
Jan 22, 2016, 12:33:09 AM1/22/16
to AdWords API Forum
Hello Roberto,

Glad to hear that.
Feel free to ask if you have any further questions.

Best,
Thanet, AdWords API Team
Reply all
Reply to author
Forward
0 new messages