谷歌加上插入活动

swa*_*pab 3 google-api google-plus ruby-on-rails-3.2 ruby-2.0 google-api-ruby-client

将活动插入谷歌加流的艰难时间.在引用谷歌开发者指南之后.我找到了一个java的例子 - https://developers.google.com/+/domains/posts/creating

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

我按照以下步骤:

通过omn​​iauth-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
Run Code Online (Sandbox Code Playgroud)

使用令牌和刷新令牌执行api调用google-api-ruby-client.能够使用"加号"列出活动,但是要插入一个我应该使用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
Run Code Online (Sandbox Code Playgroud)

使用加域

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

后来我意识到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示例

但仍然没有运气.

试试终端

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"
 }
}
Run Code Online (Sandbox Code Playgroud)

我可以在google plus user steam上插入活动获得一些帮助吗?

谢谢!

Bre*_*ttJ 5

首先要验证的事情:

  1. 您使用的是Google Apps域名.此API不适用于常规Google+用户.
  2. 您在创建客户端ID的Google API控制台中启用了Google+域名API.很容易错过Google+域名API并意外启用Google+ API.
  3. 您的Google App域必须由管理员启用Google+.
  4. 您通过标准OAuth流程或通过域范围委派代表的用户已创建Google+个人资料.

下一页:您不能将plus.login范围与Domains API一起使用.我相信你还需要删除userinfo.*范围.查看Google+域名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"
Run Code Online (Sandbox Code Playgroud)