Google plus在流上插入活动 [英] Google plus insert activity on stream
问题描述
我找到了一个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':'测试消息'}
我可以在Google plus user steam上插入活动吗? / p> 谢谢! 几项事先验证: 下一个: 另外,我相信你的范围被错误地定义了,我相信他们需要使用完整的URI: 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 I followed following steps: Define access to app via omniauth-google-oauth2 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. Using plus Domain 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 May I get some help in inserting an activity on google plus user steam ? Thanks! Couple of things to verify first: Next:
You cannot use the Also, I believe your scopes are being defined incorrectly, I believe they need to use their full URIs:
这篇关于Google plus在流上插入活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
结果在 - >
{
错误:{
错误:[
{
domain:global,
reason:禁止,
message:Forbidden
}
],
code:403,
message:Forbidden
}
}
您不能在域中使用 plus.login
作用域API。我相信你也需要删除userinfo。*作用域。请参阅 Google+ Domains API范围的完整列表。
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
activites.insert
query using google-api-ruby-client.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
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
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"
}
}
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.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"