针对Google Ads API的所有请求的内部服务器错误500

时间:2019-05-06 11:11:46

标签: google-api google-adwords google-ads-api

这是我在Node JS中的代码。

 var bearerToken = 'Bearer '+ access_token;

 var options = {
                 url: 'https://googleads.googleapis.com/v1/customers/'+accountid+'/googleAds:search',
                 headers: {
                       'Authorization': bearerToken,
                       'Accept': 'application/json',
                       'Content-Type': 'application/json',
                       'login-customer-id': '123-456-7890',
                       'developer-token': 'XXX_XXXXXXXXXXX'
                     },
                     form: { 'query': 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id' }


                   };


                   request.post(options, function(err, response) {
                       console.log(response);
                   });

我不断收到以下错误消息

body: '{\n  "error": {\n    "code": 500,\n    "message": "Internal error encountered.",\n    "status": "INTERNAL"\n  }\n}\n' }

500错误代码表示该错误来自Google。是这种情况还是我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

经过多次反复打断我的头。最后,我发现问题出在developer-token上。我必须生成一个新的developer-token并将form更改为json。现在工作正常。

这是最终的工作代码

var bearerToken = 'Bearer '+ access_token;

var options = {
             url: 'https://googleads.googleapis.com/v1/customers/'+accountid+'/googleAds:search',
             headers: {
                   'Authorization': bearerToken,
                   'Accept': 'application/json',
                   'Content-Type': 'application/json',
                   'developer-token': 'XXX_XXXXXXXXXXX'
                 },
                 json: { 'query': 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id' }


               };


               request.post(options, function(err, response) {
                   console.log(response);
               });