3

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!

4

1 回答 1

5

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"
于 2013-11-08T18:21:08.023 回答