In a nutshell, Post To enables you to provide your application users the ability to post things to MySpace. In our initial launch we’ll be offering the following Post To targets:
- Posting to the viewers profile
- Posting a bulletin
- Posting to the viewers blog
- Adding a comment
- Sending a message
Each of the targets can accept different levels of text and markup. For instance, some will accept HTML while others don’t and this is sometimes controlled by the end users privacy settings. Because of this we recommend thoroughly testing your applications.
This should go without saying but, SPAM will not be tolerated!
Overview
Post To is one of our first features that will enable you to not only help your users communicate with friends but also to start virally spreading news of your application. With just a few lines of code you can start pushing content to your users profile and friends.
Post To works by allowing you to pass a few parameters to a JavaScript function that then displays an overlay over your application (see screenshots below) . The user can then perform different actions based on the target invoked and then submit or cancel the action.
Finally, Post To is currently only available on Canvas pages.
Invoking Post To
Below we’ll go through the basics of using Post To starting with a working out of the box code example. For information on things not covered please see the http://developer.myspace.com/community/myspace/referenceIntro.aspx
Sample Code
<script type='text/javascript'>
var os_token =
MyOpenSpace.MySpaceContainer.OSToken;
var
osContainer = opensocial.Container.get();
// gets all supported post to targets
var supported
= osContainer.getMySpaceEnvironment().getSupportedPostToTargets();
var
recipientPerson;
// need a person object for add comment and send message
function init() {
dataReqObj = osContainer.newDataRequest();
dataReqObj.add(osContainer.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER));
dataReqObj.send(ownerResponse);
}
function
ownerResponse(data) {
recipientPerson = data.get(opensocial.DataRequest.PersonId.OWNER).getData();
loadSupportedTargets();
}
function
loadSupportedTargets() {
var temp =
"<select
id=\"supportedTargets\">";
for (var i = 0; i < supported.length; i++)
{
temp += "<option value=\"" + supported[ i ] + "\">" + supported[ i ] + "</option>";
}
temp += "</select>";
document.getElementById("selectInsert").innerHTML = temp;
}
function
invokePostTo(){
var
target_is_supported = false;
var target
= document.getElementById("supportedTargets").options[document.getElementById("supportedTargets").selectedIndex].value;
var
subject = "subject text";
var
content = "content text";
// make sure
that the selected target is enabled
for (var i = 0; i < supported.length; i++) {
if
(supported[ i ] === target) {
target_is_supported = true;
break;
}
}
if
(target_is_supported) {
// create
a new message object passing in the content to be posted and then set the
subject and target fields
var
message = opensocial.newMessage(content);
message.setField(opensocial.Message.Field.TITLE,
subject);
message.setField(opensocial.Message.Field.TYPE,
target);
// show
post to
osContainer.postTo(os_token,
message, recipientPerson);
}
}
init();
</script>
<div id="selectInsert"></div>
<br>
<input type="button"
onclick="invokePostTo()"
value="invoke"
/>
postTo
opensocial.Container.get().postTo(os_token, message, opt_person, opt_callback);
- os_token: The token string, this gets passed up so we can verify who's sending the request.
- Message: an opensocial.Message object. The content to be posted, the message type refers to the target of the post.
- opt_person: an opensocial.Person object. An optional opensocial.Person object, used when a recipient is required, e.g. when posting a comment, this person will get the comment.
- opt_callback: Callback function, right now just for success/fail. - not yet implemented.
openSocial.Message
Below is the function for creating a new opensocial.Message object:
var message = opensocial.newMessage(body, opt_params);
The Post To opensocial.Message message allows for three fields:
1. opensocial.Message.Field.TYPE
A supported PostTo target type from MyOpenSpace.PostTo.Targets enum. You can check if a particular target is supported by invoking: opensocial.Container.get().getMySpaceEnvironment().getSupportedPostToTargets()
Currently supported targets:
- MyOpenSpace.PostTo.Targets.PROFILE
- MyOpenSpace.PostTo.Targets.SEND_MESSAGE
- MyOpenSpace.PostTo.Targets.COMMENTS
- MyOpenSpace.PostTo.Targets.BULLETINS
- MyOpenSpace.PostTo.Targets.BLOG
Example:
message.setField(opensocial.Message.Field.Type, MyOpenSpace.PostTo.Targets.PROFILE);
2. opensocial.Message.Field.TITLE
A title for the post – this is not used in every target
Example:
message.setField(opensocial.Message.Field.TITLE, “Hello World”);
3. opensocial.Message.Field.BODY
The content you want to post.
Example:
message.setField(opensocial.Message.Field.BODY, “Hello World”);
Note: Body can also be passed in the constructor.
Target Screen Shots
Below are screen shots of the various targets with links on where you can find the corresponding MySpace feature
Posting to Profile
Posting to the users profile copies functionality found here: http://profileedit.myspace.com/index.cfm?fuseaction=profile.interests
Posting to Bulletin
Posting a bulletin copies functionality found here: http://bulletins.myspace.com/index.cfm?fuseaction=bulletin.edit
Posting to Blog
Making a blog post copies functionality found here: http://blog.myspace.com/index.cfm?fuseaction=blog.create&editor=true

Posting a Comment
Posting a comment copies functionality found here: http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=20599042

Sending a Message
Sending a message copies functionality found here: http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=20599042

Sample Application
Chris has created a handy sample application for you to see Post To in action. You can install it here: http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=364361327