Lesson 20: Post on a user's wall

From VZ Developer Wiki
Jump to: navigation, search

General Guidelines | XML Specification | Features | Views | JavaScript API | REST API | Tutorials | OAuth


Lesson 19: Send user to user messages Back to overview Lesson 21: Interacting with an additional IFrame

To post a message on a user's wall you have to call the opensocial.requestSendMessage method with a message of the type PUBLIC_MESSAGE from within your gadget.

Before the message is sent the user has to confirm this with a platform dialog.

function postToWall() {
     var params = [];
     params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE;
     var message = opensocial.newMessage('This is the message on the wall', params);
     var recipient = "VIEWER";
     opensocial.requestSendMessage(recipient, message, callback);
}

function callback(data) {
    if (data.hadError()) {
        //the user has canceled sending the message
    } else {
	//message sent
    }
}

Of course you can embed an embed view of your gadget or any static content you defined in your static_content.json file in your message. These links will be automatically replaced by the content or the gadget via an internal OEmbed resource:

vz.embed.getEmbedUrl({name: 'world'}, function(embedUrl) {
  vz.embed.getStaticContentUrl('key_resource_img', function(staticUrl) {
       var params = [];
       params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE;
       var message = opensocial.newMessage('my message ' + embedUrl + ' ' + staticUrl, params);
       var recipient = "VIEWER";
       opensocial.requestSendMessage(recipient, message, callback);
  })
});

The formats of the wall-post are the following ones:
- 300x250px for the view on the wall
- 510x500px for the detailled view


  • Lesson 20: Post on a user's wall