2014-11-21 5 views
2

Ruby API library과 함께 서비스 계정과 JWT를 사용하여 애드워즈 API 인증을 시도하는 중 오류가 발생했습니다.Google 애드워즈 API 오류 : 무효 승인

나는 example provided을 복사하고 있지만 작동하지 않는 것 같습니다.

/home/michael/.rvm/gems/ruby-2.1.2/gems/signet-0.5.1/lib/signet/oauth_2/client.rb:941:in 'fetch_access_token': 인증에 실패했습니다. 서버 메시지 : (인장 :: AuthorizationError) { "오류": "invalid_grant" }

adwords_api.yml

--- 
# This is an example configuration file for the AdWords API client library. 
# Please fill in the required fields, and copy it over to your home directory. 
:authentication: 
    # Authentication method, methods currently supported: OAUTH2, OAUTH2_JWT. 
    :method: OAUTH2_JWT 


    # Auth parameters for OAUTH2_JWT method. See: 
    # https://developers.google.com/accounts/docs/OAuth2ServiceAccount 
    :oauth2_issuer: 43242...apps.googleusercontent.com 
    :oauth2_secret: 'notasecret' 
    # You can provide path to a file with 'oauth2_keyfile' or the key itself with 
    # 'oauth2_key' option. 
    :oauth2_keyfile: /home/.../google-api-key.p12 
    # To impersonate a user set prn to an email address. 
    :oauth2_prn: [email protected] 

    # Other parameters. 
    :developer_token: ua...w 
    :client_customer_id: 123-123-1234 
    :user_agent: test-agent 
:service: 
    # Only production environment is available now, see: http://goo.gl/Plu3o 
    :environment: PRODUCTION 
:connection: 
    # Enable to request all responses to be compressed. 
    :enable_gzip: false 
    # If your proxy connection requires authentication, make sure to include it in 
    # the URL, e.g.: http://user:[email protected]_hostname:8080 
    # :proxy: INSERT_PROXY_HERE 
:library: 
    :log_level: INFO 

test.rb

#!/usr/bin/env ruby 

require 'adwords_api' 

def use_oauth2_jwt() 
    adwords = AdwordsApi::Api.new 

    adwords.authorize() 

    campaign_srv = adwords.service(:CampaignService, API_VERSION) 

    selector = { 
    :fields => ['Id', 'Name', 'Status'], 
    :ordering => [ 
     {:field => 'Name', :sort_order => 'ASCENDING'} 
    ] 
    } 

    response = campaign_srv.get(selector) 
    if response and response[:entries] 
    campaigns = response[:entries] 
    campaigns.each do |campaign| 
     puts "Campaign ID %d, name '%s' and status '%s'" % 
      [campaign[:id], campaign[:name], campaign[:status]] 
    end 
    else 
    puts 'No campaigns were found.' 
    end 
end 

if __FILE__ == $0 
    API_VERSION = :v201409 

    begin 
    use_oauth2_jwt() 

    # HTTP errors. 
    rescue AdsCommon::Errors::HttpError => e 
    puts "HTTP Error: %s" % e 

    # API errors. 
    rescue AdwordsApi::Errors::ApiException => e 
    puts "Message: %s" % e.message 
    puts 'Errors:' 
    e.errors.each_with_index do |error, index| 
     puts "\tError [%d]:" % (index + 1) 
     error.each do |field, value| 
     puts "\t\t%s: %s" % [field, value] 
     end 
    end 
    end 
end 

답변

0

몇 시간 만 더 지나면 oauth2_prn을 내 고객 센터 및 Google Apps for Business 계정의 기본 이메일로 설정하여 마침내 작동하게되었습니다.

2

이 될 것입니다 권한 기반으로 결정적으로 대답하기가 어렵 기 때문에 오류 메시지는 영광스러운 "승인되지 않은"메시지입니다.

모든 나는 정말로이 (아마 이미 이러한 겪었습니다 당신을 인정)을 확인하기 위해 몇 가지를 제안 할 것입니다 수 있습니다

  • 개발자 토큰은 확실히 '승인'으로 표시되어? (당신은 고객 센터에서 확인 가능 -, 설정 톱니를 통해 다음 다음 애드워즈 API 센터 계정) 당신이 (또는 액세스하려는 계정의 소유자가) 승인 한 Google Developer Console
  • 을 통해 응용 프로그램을 등록
  • 응용 프로그램 - 아마 somepoint에서 이러한 것들 중 하나를보고 this guide을 다음 확실히의 :

Google Auth Screen

당신이 이들 모두 체크 한 경우에만 다른 것은 내가들 수 uggest는 도움이되는 경향이있는 official forum의 게시물이며 실제 비누 요청 등을보기 위해 '오프라인'인증 요청을받는 경우가 많습니다 (애드워즈의 수준을 훨씬 더 빠르고 쉽게 파악할 수 있음). 'support')

행운을 빌어 요!