Google plus在流上插入活动 [英] Google plus insert activity on stream

查看:139
本文介绍了Google plus在流上插入活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

艰难的时间插入一个活动谷歌加流。参阅 Google开发人员指南之后。
我找到了一个java示例 - https://developers.google.com/ + / domains / posts / creating

是否有类似的例子来执行 activites.insert 使用 google-api-ruby-client 进行查询。



我遵循以下步骤:通过 omniauth-google-oauth2

  GOOGLE_CONSUMER_KEY = google_config ['KEY'] 
GOOGLE_CONSUMER_SECRET = google_config ['SECRET']
google_scope =userinfo.email,
userinfo.profile,
plus.login,
plus.me,
plus.media.upload,
plus.profiles.read,
plus.stream.read,
plus.stream.write,
plus.circles.read,
plus.circles.write

Rails.application.config.middleware.use OmniAuth :: Builder do
提供商:google_oauth2,GOOGLE_CONSUMER_KEY,GOOGLE_CONSUMER_SECRET,
{
名称:'google',
范围:google_scope,
提示:'consent'
}
结束

使用令牌和刷新令牌执行api调用 google-api-ruby-client 。我可以使用plus列出活动,但插入一个活动,我应该使用plusDomains。

  client = Google :: APIClient.new(:application_name =>'Demo GooglePlus',:application_version =>'1.0.0')

plus = client.discovered_api('plus')

plusd = client.discovered_api('plusDomain')

client_secrets = Google :: APIClient :: ClientSecrets.load

auth = client_secrets.to_authorization

:auth.update_token!(access_token:'aRandomToken',refresh_token:'aRandomRefreshToken')

result = client.execute(:api_method => plus.activities.list,:parameters => {' collection'=>'public','userId'=>'me'},:authorization => auth)
>>这样做可以返回活动列表

使用加域

  result = client.execute(:api_method => plusd.activities.insert,:parameters => {'collection'=> 'public','userId'=>'me'},:authorization => auth)
>>返回403 Forbidden

后来我意识到google api需要域范围的代理来使用域api(我认为那是正确的?)
https://developers.google.com/+/domains



https:// developers.google.com/+/domains/getting-started#accessing_the_apis - 上述步骤1中使用的oauth是否足以满足要求?

https://developers.google.com/+/domains/quickstart/python - 有没有什么可在 RUBY



我也尝试过服务帐户设置,创建了一个商业应用并遵循 service_account示例



但仍然不幸运。



在终端上试用

<$ p $ 内容类型:应用程序/ json-H授权:OAuth ya12.AqwqwwAS1212grcECQ3iVAlg-d{'object':{'content':'测试消息'}

curl -v -H < ,'access':{'items':[{'type':'domain'}],'domainRestricted':true}}-X POST https://www.googleapis.com/plus/v1domains/people/me /活动

结果在 - >
{
错误:{
错误:[
{
domain:global,
reason:禁止,
message:Forbidden
}
],
code:403,
message:Forbidden
}
}

我可以在Google plus user steam上插入活动吗? / p>

谢谢!

解决方案

几项事先验证:


  1. 您正在使用Google Apps网域。此API不适用于普通的Google+用户。

  2. 您在创建客户端ID的Google API控制台中启用了 Google+ Domains API 。您很容易错过 Google+域名API 并意外启用 Google+ API

  3. 您的Google App域必须启用Google+ 。

  4. 您代表的用户是通过代表的用户标准OAuth流程或通过域名范围代表创建了Google+个人资料。
  5. >

下一个:
您不能在域中使用 plus.login 作用域API。我相信你也需要删除userinfo。*作用域。请参阅 Google+ Domains API范围的完整列表



另外,我相信你的范围被错误地定义了,我相信他们需要使用完整的URI:

  google_scope = https://www.googleapis.com/auth/plus.me,
https://www.googleapis.com/auth/plus.media.upload,
https://www.googleapis .com / auth / plus.profiles.read,
https://www.googleapis.com/auth/plus.stream.read,
https://www.googleapis.com/auth/plus .stream.write,
https://www.googleapis.com/auth/plus.circles.read,
https://www.googleapis.com/auth/plus.circles.write


Tough time inserting an activity to google plus stream. After referring google developers guide. I found an example for java - https://developers.google.com/+/domains/posts/creating

Is there a similar example to execute the activites.insert query using google-api-ruby-client.

I followed following steps:

Define access to app via omniauth-google-oauth2

GOOGLE_CONSUMER_KEY      = google_config['KEY']
GOOGLE_CONSUMER_SECRET   = google_config['SECRET']
google_scope = "userinfo.email,
                userinfo.profile,
                plus.login,
                plus.me,
                plus.media.upload,
                plus.profiles.read,
                plus.stream.read,
                plus.stream.write,
                plus.circles.read,
                plus.circles.write"

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, GOOGLE_CONSUMER_KEY, GOOGLE_CONSUMER_SECRET,
    {
        name: 'google',
      scope: google_scope,
      prompt: 'consent'
    }
end

Use the token and refresh token to execute api calls google-api-ruby-client. Am able to list the activities using "plus", but to insert an activity I should use plusDomains.

client = Google::APIClient.new(:application_name =>'Demo GooglePlus',:application_version => '1.0.0')

plus = client.discovered_api('plus')

plusd = client.discovered_api('plusDomain')

client_secrets = Google::APIClient::ClientSecrets.load 

auth=client_secrets.to_authorization

auth.update_token!(access_token: 'aRandomToken', refresh_token: 'aRandomRefreshToken')

result = client.execute(:api_method => plus.activities.list,:parameters => {'collection' => 'public', 'userId' => 'me'}, :authorization => auth)
>> This works, returns the list of activities

Using plus Domain

result = client.execute(:api_method => plusd.activities.insert,:parameters => {'collection' => 'public', 'userId' => 'me'}, :authorization => auth)
>> Returns 403 Forbidden

Later I realized that google api requires domain wide delegaton to use the domains api(I think thats correct?) https://developers.google.com/+/domains

https://developers.google.com/+/domains/getting-started#accessing_the_apis - Will the oauth used in Step 1 above would suffice ?

https://developers.google.com/+/domains/quickstart/python - Is there anything available in RUBY

I tried the service account setup also, created a business app and followed a service_account example

But still not luck.

Trying on terminal

curl -v -H "Content-Type: application/json" -H "Authorization: OAuth ya12.AqwqwwAS1212grcECQ3iVAlg" -d "{'object':{'content':'Test message'},'access':{'items':[{'type' : 'domain'}],'domainRestricted':true}}" -X POST https://www.googleapis.com/plus/v1domains/people/me/activities

Results in ->
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

May I get some help in inserting an activity on google plus user steam ?

Thanks!

解决方案

Couple of things to verify first:

  1. You are using a Google Apps domain. This API does not work for regular Google+ users.
  2. You enabled the Google+ Domains API in the Google APIs Console where you created your client ID. It is easy to miss the Google+ Domains API and accidentally enable the Google+ API instead.
  3. Your Google App domain must have Google+ enabled by the Administrator.
  4. The user that you are acting on behalf of either through the standard OAuth flow or through domain-wide delegation has created a Google+ profile.

Next: You cannot use the plus.login scope with the Domains API. I believe you also need to drop the userinfo.* scopes. See the full list of Google+ Domains API scopes.

Also, I believe your scopes are being defined incorrectly, I believe they need to use their full URIs:

google_scope = "https://www.googleapis.com/auth/plus.me,
                https://www.googleapis.com/auth/plus.media.upload,
                https://www.googleapis.com/auth/plus.profiles.read,
                https://www.googleapis.com/auth/plus.stream.read,
                https://www.googleapis.com/auth/plus.stream.write,
                https://www.googleapis.com/auth/plus.circles.read,
                https://www.googleapis.com/auth/plus.circles.write"

这篇关于Google plus在流上插入活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆