Reputation: 312
Im trying to post some activity to a users profile in their google+.
i have been searching all the post about moments problem but still i cant solve my problem. below are my codes
$requestVisibleActions = array(
'http://schemas.google.com/AddActivity');
$client = new Google_Client();
$client->setApplicationName("PHP Google OAuth Login Example");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setDeveloperKey($simple_api_key);
$client->addScope("https://www.googleapis.com/auth/plus.login");
$client->addScope("https://www.googleapis.com/auth/plus.me");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
$client->setRequestVisibleActions($requestVisibleActions);
$plus = new Google_Service_Plus($client);
// Add Access Token to Session
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
// Set Access Token to make Request
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
}
// Post moment from mysite
if ($client->getAccessToken()) {
$moment = new Google_Service_Plus_Moment();
$moment->setType('http://schemas.google.com/AddActivity');
$itemScope = new Google_Service_Plus_ItemScope();
$itemScope->setUrl('http://developers.google.com/+/web/snippet/examples/thing');
$moment->setTarget($itemScope);
$momentResult = $plus->moments->insert('me', 'vault',$moment);
$_SESSION['access_token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
redirect($authUrl);
}
but i get a google exception error
Type: Google_Service_Exception
Message: Error calling POST
https://www.googleapis.com/plus/v1/people/me/moments/vault?key=xxxxxxx:
(400) Unable to fetch metadata.
Filename: /home2/mysite/public_html/application/libraries/google-api-php-client-master/src/Google/Http/REST.php
When i try to access the post url i get this.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
i realy dont know where im wrong. please help me
Upvotes: 2
Views: 430
Reputation: 116918
Moments: insert Record a moment representing a user's action such as making a purchase or commenting on a blog. Writing moments involves specifying the type, which is a moment type, and posting that type of moment's required fields.
Moments describe activities that users engage within your app.
Momemt types is the same as App Activity Types they are:
AddAction ,BuyAction,CheckInAction,CommentAction,CreateAction,DiscoverAction,ListenAction,ReserveAction,ReviewAction,WantAction
A moment is NOT posting to a users Google+ stream. It is NOT possible to post some activity to a users profile in their Google+.
Upvotes: 1