google-adwords-api调用

使用google adwords api的接口,在运行examples中的GetCampaigns.java时,报错了:
com.google.api.ads.common.lib.exception.OAuthException: Credential could not be refreshed. GetCampaigns 执行异常


debug了一下,发现底层的报错实际是:Connection timeout。连接超时了,也就是被墙了。

找到原因,那就好办了。

解决:先在本地开了一个socks5代理,然后添加了两行代码:
      System.setProperty("socksProxyHost", "localhost");
      System.setProperty("socksProxyPort", "58506");

丑是丑了点儿,不过先保证运行通过吧。

结果:输出了adwords内的campaignName和id

##!!!!!!!!一定要发布到正式环境!!!!!!!
##!!!!!!!!一定要发布到正式环境!!!!!!!
##!!!!!!!!一定要发布到正式环境!!!!!!!
后续:
为另一个客户新建了一个oauth同意屏幕,然后开始获取refreshtoken时,死活无法通过,后来发现oauth同意屏幕没有发布到正式环境。发布到正式环境后,重新走adwords-axis-example auth包内的GetRefreshToken.java,设置socks代理,后得到以下东西: 

Paste this url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=XXXX-YYYY.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/adwords
Type the code you received here: 
4/1AAA-bcdefejgijeofjojfoj02jf03jf0j0fj0j30fjkg4kgk00
(红色部分为网页上得到的信息,输入后回车会得到真正的refreshToken)
Your refresh token is: 1//afjoe0jf0j20j03jg0j02j0j0j0JF03J0FJ0JGF0J3G03
In your ads.properties file, modify:

api.adwords.refreshToken=1//afjoe0jf0j20j03jg0j02j0j0j0JF03J0FJ0JGF0J3G03

测试下ads是否配置成功,执行adwords.axis.v201809.basicoperations包下的GetCampaigns.java,如果成功,则可以获得如下信息:
[10 十二月 2020 10:54:40,253-requestInfoLogger:INFO:main] Request made: Service: CampaignService Method: get clientCustomerId: xxx-yyy-zzzz URL: https://adwords.google.com/api/adwords/cm/v201809/CampaignService Request ID: 5b6134c ResponseTime(ms): 271 OperationsCount: 1 IsFault: false FaultMessage: null
Campaign with name 'Android-渠道1' and ID 1111111 was found.
Campaign with name 'ios-渠道1' and ID 22222222  was found.


ads.properties中的customerId是具体账户的id,不是客户经理的id