我开始在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) 我想获得当前网页的Google + 1s数量?我想在PHP中执行此过程,然后将数量的共享或+ 1s写入数据库.这就是为什么,我需要它.那么,我怎样才能在PHP中完成这个过程(获得+ 1s的数量)?
提前致谢.
好了,这个问题已经被问过这里.在响应/问题的答案,用户告诉他存储refresh_token在应用程序(会话,而不是数据库,但不要紧,你保存它).在浏览了Google上的文档后,似乎access_token有一个到期日期,之后它就不再有效了.现在,我们显然可以在每个固定的时间间隔内自动刷新令牌,或者如果服务返回无效的令牌错误,从而延长令牌的生命周期,但由于某种原因,这个手动过程感觉有点hacky.我的问题是:
我尝试刷新访问令牌时收到错误:
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)
有什么不对的吗?
我想在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) 我正在使用Python中的Google Tasks API编写程序.我已经从Google下载并运行了示例应用程序,它附带了一个名为"client_secrets.json"的文件.我知道该文件用于0Auth身份验证,但我的问题是我应该将此文件分发给用户吗?我应该把它推到我的公共来源回购中吗?或者它应该被保密?如果我不应该分享,其他用户将如何进行身份验证?
谢谢阅读.
我正在为新的律师事务所创建一个新的网站.
我按照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:

我如何能:
我使用新的Gmail API为我的用户创建草稿.API响应提供新创建的消息ID.
然后我可以用URL打开撰写窗口https://mail.google.com/mail/#drafts?compose=[message-id].但是我想打开一个全屏(弹出)组合窗口.是否有URL?当然,必须使用消息ID对此URL进行参数化.
我正在尝试使用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) 我在Google Developer Console中有几个项目,我只是一个查看器.我可以将自己从他们身上移开,或隐藏起来吗?
google-api ×10
api ×2
javascript ×2
oauth-2.0 ×2
calendar ×1
email ×1
gmail ×1
gmail-api ×1
google-maps ×1
google-plus ×1
html ×1
maps ×1
oauth ×1
php ×1
python ×1