Похоже, что в настоящее время API-интерфейс API не работает с записью активности приложения в Google, поскольку он не передает поле requestvisibleactions в поток OAUTH2. Вы все еще можете делать что-то вручную, как я опишу ниже.
Есть две вещи, которые нужно сделать:
Во-первых, убедитесь, что вы оказываете кнопку входа в с requestvisibleactions, установленным для видов деятельности приложения вы вставляете. В следующем примере показано, как будет оказывать вход с надстройкой деятельности:
<div id="gConnect">
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-clientId="YOUR_CLIENT_ID"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
</div>
Далее, вам нужно будет построить и написать приложение деятельности. Следующий пример показывает это с помощью JavaScript:
var payload = {
"target": {
"id" : "replacewithuniqueidforaddtarget",
"image" : "http:\/\/www.google.com\/s2\/static\/images\/GoogleyEyes.png",
"type" : "http:\/\/schema.org\/CreativeWork",
"description" : "The description for the activity",
"name":"An example of AddActivity"
},
"type":"http:\/\/schemas.google.com\/AddActivity",
"startDate": "2012-10-31T23:59:59.999Z"
};
var args = {
'path': '/plus/v1/people/me/moments/vault',
'method': 'POST',
'body': JSON.stringify(payload),
'callback': function(response) {
console.log(response);
}
};
gapi.client.request(args);
Вы можете увидеть живую демонстрацию здесь:
http://wheresgus.com/appactivitiesdemo
Вы можете узнать о всех видов деятельности из документации здесь:
https://developers.google.com/+/api/moment-types
Обновление
Обратите внимание на демо было обновлено с помощью следующего кода, и вы не должны быть прямым вызовом gapi.client.request:
writeListenActivity: function(url){
var payload = {
"type": "http://schemas.google.com/ListenActivity",
}
if (url != undefined){
payload.target = { 'url' : url };
}else{
payload.target = {
"type": "http:\/\/schema.org\/MusicRecording",
"id": "uniqueidformusictarget",
"description": "A song about missing one's family members fighting in the American Civil War",
"image": "https:\/\/developers.google.com\/+\/plugins\/snippet\/examples\/song.png",
"name": "When Johnny Comes Marching Home"
};
}
this.writeAppActivity(payload);
},
writeAddActivity: function(url){
var payload = {
"type":"http:\/\/schemas.google.com\/AddActivity",
"startDate": "2012-10-31T23:59:59.999Z"
};
if (url != undefined){
payload.target = {
'url' : 'https://developers.google.com/+/plugins/snippet/examples/thing'
};
}else{
payload.target = {
"id" : "replacewithuniqueidforaddtarget",
"image" : "http:\/\/www.google.com\/s2\/static\/images\/GoogleyEyes.png",
"type" : "http:\/\/schema.org\/CreativeWork",
"description" : "The description for the activity",
"name":"An example of AddActivity"
};
}
this.writeAppActivity(payload);
},
writeAppActivity: function(payload){
gapi.client.plus.moments.insert(
{ 'userId' : 'me',
'collection' : 'vault',
'resource' : payload
}).execute(function(result){
console.log(result);
});
}
Особо следует отметить код gapi.client.plus.moments.insert который заменяет вызов gapi.client.request.
Отлично, выглядит как 'requestvisibleactions' является корнем проблемы. И [этот пост] (https://plus.google.com/118276561380249048216/posts/2kMX9Dzaf8V) приводит к правильному [diff] (https://code.google.com/p/google-api-php-client/source /diff?spec=svn533&r=533&format=side&path=/trunk/src/auth/Google_OAuth2.php) для аутентификации на стороне сервера. Спасибо за информацию! – mente
@class Что вы подразумеваете под «replacewithuniqueidforaddtarget», вы просто вводите случайный идентификатор здесь или еще что-то? – Supertecnoboff
Для целевого id, это просто случайная строка, как вы предполагали. – class