401通过PHP客户端发布Google+ Moments时未经授权的访问 [英] 401 Unauthorized access when posting Google+ Moments with PHP Client
问题描述
我正在尝试使用API在google +中发布消息,创建一个简单的示例,但出现401错误.我正在从 https://plus.google.com/+SilvanoLuciani/posts/2kMX9Dzaf8V ,为了发表一点,我已经:
I'm trying to post a moment in google+ using the API, creating a simple example, but I get a 401 error. I'm following Silvano Luciani steps from https://plus.google.com/+SilvanoLuciani/posts/2kMX9Dzaf8V, and in order to post a moment, I've:
-
从此处下载了最后一个库0.6.1:从Silvano Luciani下载的示例: https://gist.github.com/silvolu/5054214
Downloaded example from Silvano Luciani: https://gist.github.com/silvolu/5054214
使用来自我的G +应用的所有数据配置示例文件
Configured the example file with all the data from my G+ App
这直接不起作用,在示例的第16行中,它要求一个类 Google_PlusService ,并且该类不存在,因此我将其更改为类 Google_PlusMomentsService .
This directly doesn't work, in the example, in line 16, is asking for a class Google_PlusService, and it doesn't exist, so I changed it for the class Google_PlusMomentsService.
进行更改后,它会发布到类似于'plus/v1moments/people/'的URL,并显示404错误.因此,我将 src/contrib/Google_PlusMomentsService.php 中的URL从"plus/v1moments/people" =>修改为"plus/v1/人" .
With the change, it posted to a URL that is something like 'plus/v1moments/people/' and it shows 404 error. So, I modified the URL in src/contrib/Google_PlusMomentsService.php, line 73 from "plus/v1moments/people" => to "plus/v1/people".
此后,它表明它需要 setRequestVisibleActions 才能工作,并且我意识到Google客户端没有该方法,因此我从此处的Google存储库中获取了最后一个Google_client: https://code.google.com/p/google- api-php-client/source/detail?r = 534
After that, it shows that it requires setRequestVisibleActions to work, and I realized the Google Client hasn't the method, so I take the last Google_client from the Google repo here: https://code.google.com/p/google-api-php-client/source/detail?r=534
好,现在可以了,但是显示401错误,我不知道该怎么做.
Ok, now, it works but it shows a 401 error and I don't know how to follow.
错误是:
调用POST https://www时出错. googleapis.com/plus/v1/people/me/moments/vault?key=XXXXXXXXXXXXXX :(401)在第66行的C:\ wamp \ www \ gPlus \ src \ io \ Google_REST.php中未经授权>
Error calling POST https://www.googleapis.com/plus/v1/people/me/moments/vault?key=XXXXXXXXXXXXXX: (401) Unauthorized in C:\wamp\www\gPlus\src\io\Google_REST.php on line 66
其中XXXXXXXXXX密钥是我在文件中设置的开发者密钥.看起来POST没有在URL中包含操作,但是我不确定这是问题还是如何解决.有谁知道如何解决吗?谢谢!
Where XXXXXXXXXX key is my developer key set in the file. It looks like the POST is not including the actions in the URL, but I'm not sure if this is the problem or how to solve it. Has anyone any idea of how to solve it? Thanks!
正如Luciano所指出的那样,我正在使用一个过时的google-php-client,因此,正如他所指出的,我已经从SVN存储库下载了最后一个代码.但是,在设置完配置文件之后,暂时添加来自Silvano的即时示例文件,并在Google控制台和配置文件中配置API重定向URL,/examples文件夹中的示例将无法正常工作.执行Silvano PHP示例时,抛出不可用"错误:
As Luciano is pointing, I'm using an obsolete google-php-client, so, as he indicates, I've downloaded from the SVN repo the last code. But after setting the configuration files, include the moments example file from Silvano in moments and configure the API redirects URL in the Google console and the config files, the examples in /examples folder are not working. Executing Silvano PHP example it's throwing a "Not available" error:
Esta página web no está disponible Es posible que la página web https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2FgplusAPI%2Fexamples%2Fmoments%2Findex.php&client_id=xxxxxxxx.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login&access_type=offline&approval_prompt=force&request_visible_actions=http%3A%2F%2Fschemas.google.com%2FAddActivity+http%3A%2F%2Fschemas.google.com%2FReviewActivity esté temporalmente inactiva o que se haya trasladado definitivamente a otra dirección. Error 15 (net::ERR_SOCKET_NOT_CONNECTED): Error desconocido.
但是该库中的其他示例也有相同的错误.时间问题还是图书馆问题?
But also the same error with the other examples in the library. A temporal problem, or a library problem?
是的,这是浏览器问题.它仍然会出现在Chrome中,但是使用Firefox就像是一种魅力,它不再出现401错误,这很好,XD
Yeah, it was a browser problem. It still appearing in Chrome, but using Firefox is working like a charm, it doesn't appears 401 error anymore, which is good, XD
现在,我还有另一个问题,它会返回一个数组,但不会在流中发布任何内容.西尔瓦诺,这正常吗?无论如何,非常感谢您的帮助,我的主要问题得到了回答,而完成流发布的第二步,就是XD!
Now, I have another problem, it gives back an array but it doesn't publish anything in the stream. Silvano, is this normal? Anyway, thank you very much for your help, my main question is answered, another step less to accomplish stream publishing, XD!
该数组是:
Array ( [kind] => plus#moment [type] => http://schemas.google.com/AddActivity [target] => Array ( [kind] => plus#itemScope [url] => https://developers.google.com/+/plugins/snippet/examples/thing ) [result] => Array ( [kind] => plus#itemScope ) [id] => xxxxxxxxx )
更新3
好的,为了防止垃圾邮件,他们不允许直接在信息流中发帖.有关更多信息,请参见此问题的答案:
Update 3
Ok, It looks that to prevent spam they don't allow post directly on stream. See the answer of this question for more info:
推荐答案
You need to use the version of the library that you can find in trunk for the code shown in the gist to work.
您不应使用Google_PlusMomentsService,因为它已被弃用(并且已从主干中删除).奇怪的是Google_PlusService不存在,它是此处.
You shouldn't use Google_PlusMomentsService, because it has been deprecated (and it's removed from trunk). It's strange that Google_PlusService doesn't exist, it's here.
这篇关于401通过PHP客户端发布Google+ Moments时未经授权的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!