2014-11-02 1 views
1

를 redirect_uri로 나는 개발자 콘솔에서 다음 JSON을 얻었다.프로비저닝 API는 내가 "설치된 응용 프로그램 방법"을 사용 나는 인증의</p> <p><a href="https://developers.google.com/analytics/devguides/config/provisioning/v3/devguide" rel="nofollow">https://developers.google.com/analytics/devguides/config/provisioning/v3/devguide</a>을 사용하고

{ 
    "installed":{ 
      "auth_uri":"https://accounts.google.com/o/oauth2/auth", 
      "client_secret":"MYSECRET", 
      "token_uri":"https://accounts.google.com/o/oauth2/token", 
      "client_email":"", 
      "redirect_uris":["urn:ietf:wg:oauth:2.0:oob","oob"], 
      "client_x509_cert_url":"", 
      "client_id":"MY CLIENT ID", 
      "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs" 
     } } 

내가 좋아하는 뭔가를해야 문서에 따르면

나는 응답이 localhost로 redirect_uri로 설정
import httplib2 
from apiclient.discovery import build 
from oauth2client.file import Storage 

def create_account_ticket(service): 
    """for the body see 
    https://developers.google.com/analytics/devguides/config/provisioning/v3/devguide 
    search for Create an Account Ticket using the Provisioning API 
    and take a look at: 
    https://developers.google.com/resources/api 
    libraries/documentation/analytics/v3/python/latest/analytics_v3.provisioning.html 
    """ 
    body_ = {'redirectUri': 'http://localhost', 
      'account': {'name': "My Account Name"}, 
      'webproperty': {'name': 'What kind of name?', 
          'websiteUrl': 'http://www.mywebsite.de'}, 
      'profile': {'name': 'My Profile name', 'timezone': "Europe/Berlin"}, 
      } 

    res = service.provisioning().createAccountTicket(body=body_).execute() 
    return res 


if __name__ == '__main__': 
    storage = Storage('FileContainingToken.dat') 
    credentials = storage.get() 
    http = httplib2.Http() 
    http = credentials.authorize(http) 
    service = build('analytics', 'v3', http=http) 
    t = create_account_ticket(service) 

:

HttpError : HTTPS : //www.googleapis. com/analytics/v3/provisioning/createAccountTicket? alt = json returned "필드 값 redirectUrl = 'http : // localhost'가 유효하지 않습니다.">

내가 예상대로 얻을 redirect_uri로를 가져 가십시오 : 는 "필드는 URI가 필요한 리디렉션"

https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi

localhost

This value signals to the Google Authorization Server that the authorization code should be returned as a query string parameter to the web server on the client

에 따르면 그래서이 redirect_uri로는 유효해야합니다.

규정에 따라 API 문서

Redirect URI - This is where the user is redirected to and the OAuth 2.0 response is sent. Configure Redirect URIs and obtain the Client ID for your project using the Google Developers Console. The value of this parameter must exactly match one of the values registered in the Google Developers Console (including the http or https schemes, case, and trailing '/').

어떻게이 (가) 프로비저닝 API 및 로컬 호스트가 유효하지 않은 이유에 대한 URI를 재 지정할 수 있습니다?

답변

1

나는 아직 코멘트를 남길 수 없기 때문에이 답변으로 남겨 둘 것입니다. 이 있지만 그냥 한눈에

body_ = {'redirectUri': 'http//localhost',

,

http//localhost should be http://localhost 
+0

덕분에, 당신은 여전히 ​​문제가 있다면 난 그냥 궁금 헤이 볼 – gosom

+0

지적 SO.thanks에 붙여 넣은 코드에 오타입니다 이걸로. ** http : // localhost **는 완료되지 않았기 때문에 유효하지 않습니다. ** http : //localhost.com**이어야합니다. – SirLoyn