0
votes

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:

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.

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".

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

Ok, now, it works but it shows a 401 error and I don't know how to follow.

The error is:

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

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!

Update

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?

Update 2

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

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!

The array is:

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 
) 

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:

Post in Google+ stream is not showing up in user's stream using google-api-PHP-client

1

1 Answers

2
votes

You need to use the version of the library that you can find in trunk for the code shown in the gist to work.

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.