Google AdWords图书馆不会创建访问令牌

时间:2018-04-18 18:29:00

标签: c# asp.net .net api google-api

我正在尝试对Google AdWords进行 targetingIdeaService API调用。到目前为止,这是我的代码:

[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" };
    }
}

它看起来不错,最后编译,依此类推。但后来我进入了调试模式。我看到了这个:

enter image description here

您可以看到,该变量没有 访问令牌 。其他数据来自app.config文件。

我很确定传入的密钥是正确的。

然后代码抛出了着名的invalid_grand错误。就我而言,我认为这是因为没有生成访问令牌。我是AdWords和ASP.NET的新手,所以我可能错过了一些东西,但我不知道是什么。

我用了 docsCode Structure instructions,和 code examples将它们放在一起。

1 个答案:

答案 0 :(得分:0)

我的配置错误了。我不得不使用隐身窗口重新创建所有凭据。如果您有任何问题,请在此处打开一个帖子:https://groups.google.com/forum/#!forum/adwords-api