googleoauth和local d

2024-06-16 12:30:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用googleoauth导入用户的联系人。为了获得你的应用程序的消费者和密钥,你必须在https://www.google.com/accounts/ManageDomains验证你的域名。谷歌允许你只使用没有端口的域。我想在本地测试和构建应用程序,所以通常(Facebook、Linkedin应用程序)我使用反向SSH隧道,例如http://6pna.com:30002

有人使用谷歌OAuth的隧道吗。有用吗?到目前为止,我只是验证了我的应用程序域,但是我的请求来自隧道(不同的域),所以OAuth失败了(尽管我进入了Google并授权了我的应用程序)

有什么提示吗?谢谢


Tags: 用户httpscom应用程序wwwgoogle密钥联系人
2条回答

经过反复试验,我发现请求的域是不相关的

我只使用官方的gdatagoogleauth库http://code.google.com/p/gdata-python-client

这里有一些代码

    google_auth_url = None
    if not current_user.gmail_authorized:
        google = gdata.contacts.service.ContactsService(source=GOOGLE_OAUTH_SETTINGS['APP_NAME'])
        google.SetOAuthInputParameters(GOOGLE_OAUTH_SETTINGS['SIG_METHOD'], GOOGLE_OAUTH_SETTINGS['CONSUMER_KEY'],
                                      consumer_secret=GOOGLE_OAUTH_SETTINGS['CONSUMER_SECRET'])
        if not request.vars.oauth_verifier:
            req_token = google.FetchOAuthRequestToken(scopes=GOOGLE_OAUTH_SETTINGS['SCOPES'],
                          oauth_callback="http://"+request.env.http_host+URL(r=request,c='default',f='import_accounts'))
            session['oauth_token_secret'] = req_token.secret
            google_auth_url = google.GenerateOAuthAuthorizationURL()
        else:
            oauth_token = gdata.auth.OAuthTokenFromUrl(request.env.request_uri)
            if oauth_token:
                oauth_token.secret = session['oauth_token_secret']
                oauth_token.oauth_input_params = google.GetOAuthInputParameters()
                google.SetOAuthToken(oauth_token)
                access_token = google.UpgradeToOAuthAccessToken(oauth_verifier=request.vars.oauth_verifier)
                # store access_tonen

        #google.GetContactsFeed() # do the process or do it in ajax (but first update the user)

相关问题 更多 >