将活动插入谷歌加流的时间过长。在提到google developers guide之后。 我找到了一个java的例子 - https://developers.google.com/+/domains/posts/creating
是否有使用google-api-ruby-client执行activites.insert
查询的类似示例。
我按照以下步骤操作:
定义对应用的访问权限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
使用令牌和刷新令牌执行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
使用加号域
result = client.execute(:api_method => plusd.activities.insert,:parameters => {'collection' => 'public', 'userId' => 'me'}, :authorization => auth)
>> Returns 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 example
但仍然没有运气。
尝试使用终端
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"
}
}
我可以在google plus user steam上插入活动获得一些帮助吗?
谢谢!
答案 0 :(得分:5)
首先要验证的事情:
下一步:
您不能将plus.login
范围与Domains API一起使用。我相信你还需要删除userinfo。*范围。请参阅full list of Google+ Domains API scopes。
另外,我认为你的范围定义不正确,我相信他们需要使用他们的完整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"