当用户使用google plus凭据登录我的Ruby on Rails应用程序时,我想将消息发布到google plus。
我尝试过以下代码。
<script src="/../assets/plusone.js"></script>
<script type="text/javascript">
function writeAddActivity(url){
var payload = {
"type":"http:\/\/schema.org\/AddAction",
"startDate": "2012-10-31T23:59:59.999Z"
};
if (url != undefined){
payload.object = {
'url' : "https://plus.google.com/js/client:plusone.js"
};
}else{
payload.object = {
"id" : "replacewithuniqueidforaddtarget",
"image" : "http:\/\/www.google.com\/s2\/static\/images\/GoogleyEyes.png",
"type" : "http:\/\/schema.org\/CreativeWork",
"description" : "The description for the action",
"name":"An example of AddAction",
"src" : "https://plus.google.com/js/client:plusone.js"
};
}
gapi.client.plus.moments.insert(
{ 'userId' : 'me',
'collection' : 'vault',
'resource' : payload
}).execute(function(result){
console.log(result);
});
}
但它给出了&#34; TypeError:gapi.client.plus未定义&#34; 。你能解释一下错误是什么以及解决方法吗?提前谢谢。
答案 0 :(得分:4)
要加载gapi.client,您需要调用
gapi.load('client', function() {
console.log('gapi.client loaded.');
});
要加载gapi.client.plus,您需要调用
gapi.client.load('plus', 'v1').then(function() {
console.log('gapi.client.plus loaded.');
});