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!