Vijikumar M
Vijikumar M

Reputation: 3764

TypeError: gapi.client.plus is undefined

I want to post message to google plus when a user logged in my Ruby on Rails application with his google plus credentials.

I have tried the following code.

 <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);
  });

}

But it's giving "TypeError: gapi.client.plus is undefined" . Could you explain what is the error and how to resolve it? Thanks in advance.

Upvotes: 1

Views: 2031

Answers (1)

Jarosław Gomułka
Jarosław Gomułka

Reputation: 4985

To load gapi.client you need to call

gapi.load('client', function() { console.log('gapi.client loaded.'); });

To load gapi.client.plus you need to call

gapi.client.load('plus', 'v1').then(function() { console.log('gapi.client.plus loaded.'); });

Upvotes: 4

Related Questions