问题描述
我正在尝试对 Google AdWords 进行 targetingIdeaService API 调用.到目前为止,这是我的代码:
I'm trying to make a targetingIdeaService API call to Google AdWords. This is my code so far:
[HttpGet]
public IEnumerable<string> Get()
{
var user = new AdWordsUser();
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
{
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.requestType = RequestType.IDEAS;
selector.ideaType = IdeaType.KEYWORD;
selector.requestedAttributeTypes = new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION,
AttributeType.CATEGORY_PRODUCTS_AND_SERVICES
};
// Set selector paging (required for targeting idea service).
var paging = Paging.Default;
// Create related to query search parameter.
var relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter
{ queries = new String[] { "bakery", "pastries", "birthday cake" } };
var searchParameters = new List<SearchParameter> { relatedToQuerySearchParameter };
var page = new TargetingIdeaPage();
page = targetingIdeaService.get(selector);
return new string[] { "value1", "value2" };
}
}
看起来没问题,终于可以编译了,等等.但后来我进入了调试模式.我看到了这个:
it looks ok, compiles at last, and so on. But then I went into debug mode. And I saw this:
如您所见,该变量没有访问令牌.其他数据来自 app.config
文件.
So as you can see, the variable doesn't have the access token. The other data comes from app.config
file.
我很确定传入的密钥是正确的.
I am quite certain the keys passed in are correct.
然后代码抛出著名的 invalid_grand
错误.就我而言,我认为这是因为未生成访问令牌.我是 AdWords 和 ASP.NET 的新手,所以我可能错过了一些东西,但我不知道是什么.
Then the code throws the famous invalid_grand
error. In my case, I believe that's because the access token is not being generated. I'm new to AdWords and ASP.NET, so I probably missed something, but I have no idea what.
I used thedocs,Code Structure instructions, andcode examples to put it all together.
推荐答案
我的配置有误.我不得不使用隐身窗口重新创建所有凭据.如果您有任何问题,请在此处打开一个线程:https://groups.google.com/forum/#!forum/adwords-api
I had my configuration wrong. I had to recreate all the credentials using incognito window. If you have any issues just open a thread here: https://groups.google.com/forum/#!forum/adwords-api
这篇关于Google AdWords 库不会创建访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!