标签: google-api

在localhost上使用Google OAuth

我开始在Python和Django中使用OAuth.我需要它用于Google API.我在localhost上工作,所以我无法为url-callback注册域名.我读过Google OAuth可以与匿名域一起使用.找不到,我怎么能和在哪里做到这一点?

编辑:

我有这个观点:

def authentication(request):
    CONSUMER_KEY = 'xxxxx'
    CONSUMER_SECRET = 'xxxxx'
    SCOPES = ['https://docs.google.com/feeds/', ]

    client = gdata.docs.client.DocsClient(source='apiapp')
    oauth_callback_url = 'http://%s/get_access_token' % request.META.get('HTTP_HOST')
    request_token = client.GetOAuthToken(
      SCOPES, oauth_callback_url, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)
   domain = '127.0.0.1:8000'
   return HttpResponseRedirect(
        request_token.generate_authorization_url(google_apps_domain=domain))
Run Code Online (Sandbox Code Playgroud)

而这个错误:

抱歉,您已到达未使用Google Apps的域的登录页面.请检查网址,然后重试.

通过https://code.google.com/apis/console/注册

编辑:

CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
SCOPES = ['https://docs.google.com/feeds/', ]
DOMAIN = 'localhost:8000'


def authentication(request):    
    client = gdata.docs.client.DocsClient(source='apiapp')
    oauth_callback_url = 'http://%s/get_access_token' % DOMAIN

    request_token = client.GetOAuthToken(SCOPES,
                                     oauth_callback_url,
                                     CONSUMER_KEY,
                                     consumer_secret=CONSUMER_SECRET)

    return HttpResponseRedirect(
        request_token.generate_authorization_url())


def verify(request):
    client …
Run Code Online (Sandbox Code Playgroud)

python oauth google-api google-api-client

18
推荐指数
1
解决办法
1万
查看次数

如何在PHP中获取当前页面的+1 +1?

我想获得当前网页的Google + 1s数量?我想在PHP中执行此过程,然后将数量的共享或+ 1s写入数据库.这就是为什么,我需要它.那么,我怎样才能在PHP中完成这个过程(获得+ 1s的数量)?
提前致谢.

php api google-api google-plus-one google-plus

18
推荐指数
5
解决办法
2万
查看次数

如何自动登录Google API以获取OAuth 2.0令牌以访问已知用户帐户

好了,这个问题已经被问过这里.在响应/问题的答案,用户告诉他存储refresh_token在应用程序(会话,而不是数据库,但不要紧,你保存它).在浏览了Google上的文档后,似乎access_token有一个到期日期,之后它就不再有效了.现在,我们显然可以在每个固定的时间间隔内自动刷新令牌,或者如果服务返回无效的令牌错误,从而延长令牌的生命周期,但由于某种原因,这个手动过程感觉有点hacky.我的问题是:

  • 这是通过在应用程序中手动登录并保留令牌来访问已知用户帐户的Google日历/应用程序数据的最有效(/普遍接受)方式吗?或者是否有其他机制允许我们以编程方式登录此用户帐户并完成OAuth步骤?

google-calendar-api google-api oauth-2.0

18
推荐指数
1
解决办法
2万
查看次数

无法刷新访问令牌:响应是"unauthorized_client"

我尝试刷新访问令牌时收到错误:

400错误请求

{error:"unauthorized_client"}

来自Google令牌URI:

{
  "error" : "invalid_request"
}
Run Code Online (Sandbox Code Playgroud)

在这里阅读了这个答案以及官方的Google文档(描述了POST请求应该如何看待),我没有看到任何区别.

我抓住了我的POST请求(删除了秘密):

POST /SHOWMERAWPOST HTTP/1.1
User-Agent: Google-HTTP-Java-Client/1.10.3-beta (gzip)
Pragma: no-cache
Host: requestb.in
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 175
Connection: keep-alive
Cache-Control: no-cache
Accept-Encoding: gzip
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

grant_type=refresh_token&refresh_token=******&client_id=*******.apps.googleusercontent.com&client_secret=******
Run Code Online (Sandbox Code Playgroud)

发送请求的Java代码:

RefreshTokenRequest req = new RefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(), new GenericUrl(
                    getSecrets().getDetails().getTokenUri()), REFRESH_TOKEN);

           req.set("client_id", getSecrets().getDetails().getClientId());
           req.set("client_secret", getSecrets().getDetails().getClientSecret());

           TokenResponse response = req.execute();
Run Code Online (Sandbox Code Playgroud)

有什么不对的吗?

google-api oauth-2.0 google-api-java-client

18
推荐指数
2
解决办法
3万
查看次数

Javascript中的Google API

我想在javascript中从谷歌获取日历信息.我读过"如何"手册.他们没有帮助.即使这种"有用的"复制代码(授权)也没有.有人会这么好教我如何使用谷歌API?也许某人有一些样本要分享

这个美丽的js代码:

<html>
<button id="authorize-button" onclick='handleAuthClick()'>Authorize</button>

<script type="text/javascript">
    var clientId = '***';
    var apiKey = '***';
    var scopes = 'https://www.googleapis.com/auth/plus.me';

    function handleClientLoad() {
        gapi.client.setApiKey(apiKey);
        window.setTimeout(checkAuth,1);
    }

    function checkAuth() {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
    }

    function handleAuthResult(authResult) {
        var authorizeButton = document.getElementById('authorize-button');
        if (authResult && !authResult.error) {
            authorizeButton.style.visibility = 'hidden';
            makeApiCall();
        } else {
            authorizeButton.style.visibility = '';
            authorizeButton.onclick = handleAuthClick;
        }
    }

    function handleAuthClick(event) {
        // Step 3: get authorization to use private data
        gapi.auth.authorize({client_id: clientId, scope: scopes, …
Run Code Online (Sandbox Code Playgroud)

javascript google-api

18
推荐指数
1
解决办法
2万
查看次数

client_secrets.json文件的用法是什么?

我正在使用Python中的Google Tasks API编写程序.我已经从Google下载并运行了示例应用程序,它附带了一个名为"client_secrets.json"的文件.我知道该文件用于0Auth身份验证,但我的问题是我应该将此文件分发给用户吗?我应该把它推到我的公共来源回购中吗?或者它应该被保密?如果我不应该分享,其他用户将如何进行身份验证?

谢谢阅读.

google-api

18
推荐指数
2
解决办法
1万
查看次数

将自定义标记文本添加到Google地图

我正在为新的律师事务所创建一个新的网站.

我按照Google API嵌入了地图.我添加了他们的地址,但想将公司的名称添加到地图中...您可以在地图中看到,它不会捕获名称:

<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key=myapikey&q=883%20Farmington%20Avenue%2C%20Berlin%2C%20CT%2006037%2C%20United%20States"></iframe>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

所以,我尝试在iframe中的地址前添加一个名称:

q=Jill+Levin+Law,address here...

但我猜这个关键词会Levin选择匹配的公司,Soulsby & Levin, LLC...即使我没有改变地址

<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key=myapikey&q=Jill+Levin+Law,883%20Farmington%20Avenue%2C%20Berlin%2C%20CT%2006037%2C%20United%20States"></iframe>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

即使Google API本身也会根据关键字选择错误的API:

在此输入图像描述

我如何能:

  • 让Google地图选择正确的办公室名称
  • 如果尚未定义办公室名称,我怎样才能简单地将文本名称添加到标记的顶部?

html javascript maps google-maps google-api

18
推荐指数
1
解决办法
1万
查看次数

是否有用于以全屏(弹出)方式打开具有特定消息ID的Gmail撰写窗口的URL

我使用新的Gmail API为我的用户创建草稿.API响应提供新创建的消息ID.

然后我可以用URL打开撰写窗口https://mail.google.com/mail/#drafts?compose=[message-id].但是我想打开一个全屏(弹出)组合窗口.是否有URL?当然,必须使用消息ID对此URL进行参数化.

更确切地说,这就是我得到的,这就是我想要的.

email gmail google-api google-api-client gmail-api

18
推荐指数
1
解决办法
2759
查看次数

未配置Google Calendar API v3访问权限

我正在尝试使用Google API的v3从客户的公共日历中获取事件列表.我将日历ID输入API Explorer,我得到了一个积极的结果:

https://www.googleapis.com/calendar/v3/calendars/rpsj44u6koirtq5hehkt21qs6k%40group.calendar.google.com/events?key={YOUR_API_KEY}`

=> [List of events here, as expected]
Run Code Online (Sandbox Code Playgroud)

为了创建API密钥,我在Google Developer Console中创建了一个项目,创建了一个公共API访问密钥(API&auth> Credentials),并{YOUR_API_KEY}在上面替换为我的实际密钥.我确保打开了Calendar API(API和auth> API).当我在浏览器中粘贴此URL时,我收到此错误响应:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
    "extendedHelp": "https://console.developers.google.com" …
Run Code Online (Sandbox Code Playgroud)

api calendar google-calendar-api google-api

18
推荐指数
3
解决办法
2万
查看次数

如何从Google Developer Console中的项目中删除自己?

我在Google Developer Console中有几个项目,我只是一个查看器.我可以将自己从他们身上移开,或隐藏起来吗?

google-app-engine google-api google-compute-engine

18
推荐指数
2
解决办法
2337
查看次数