Here's code that should post a notification (OpenSocial 0.7!):
function sendNotification() {
var params = {};
params[opensocial.Message.Field.TITLE] =
"Title of the notification goes here";
params[opensocial.Message.Field.TYPE] =
opensocial.Message.Type.PRIVATE_MESSAGE;
var body="Text of the notification goes here";
var message = opensocial.newMessage(body, params);
var recipient = opensocial.DataRequest.PersonId.OWNER;
opensocial.requestSendMessage(recipient, message,
onSendNotification);
};
function onSendNotification(resp) {
if (!resp.hadError() && resp.getData().status == "sent") {
alert("The message was sent to the OWNER");
} else {
alert("There was a problem: " + resp.getErrorMessage());
}
};
sendNotification();
Here's code that should post an activity:
function sendActivity() {
var activityParams = {};
activityParams[opensocial.Activity.Field.TITLE] =
'Test activity';
var mediaItems = new Array();
var mediaItem = opensocial.newActivityMediaItem(
opensocial.Activity.MediaItem.Type.IMAGE,
"http://www.google.com/images/logo_sm.gif");
mediaItems.push(mediaItem);
activityParams[opensocial.Activity.Field.MEDIA_ITEMS] =
mediaItems;
var activity = opensocial.newActivity(activityParams);
opensocial.requestCreateActivity(activity, "HIGH",
onActivitySent);
};
function onActivitySent(data) {
if (data.hadError()) {
alert("Could not send activity update: " +
data.getErrorMessage());
} else {
alert("The Activity was sent");
}
};
sendActivity();
If these don't work, let me know what container you're working on-
activities or notifications may not be supported.
~Arne
On Sep 24, 7:43 am, mabel <[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I created a small application and I am trying to send users and users'
> friends notifications but I failed and also I couldn't display any
> activity.
>
> Here is my code:
>
> For notifications:
>
> var params = {};
> params[opensocial.Message.Field.TITLE]="My Game";
> params[opensocial.Message.Field.TYPE]
> =opensocial.Message.Type.NOTIFICATION;
> var body="Tanadu";
> var message = opensocial.newMessage(body, params);
> var recipient = toIds;
> opensocial.requestSendMessage(recipient, message,
> onSendNotification);
>
> and for activities:
>
> var activityParams = {};
> activityParams[opensocial.Activity.Field.TITLE] = 'Enjoy the
> Game';
>
> var mediaItems = new Array();
> var mediaItem =
> opensocial.newActivityMediaItem(opensocial.Activity.MediaItem.Type.IMAGE,
> viewer.getField(opensocial.Person.Field.THUMBNAIL_URL));
> // Add a media item link if supported
> mediaItems.push(mediaItem);
> activityParams[opensocial.Activity.Field.MEDIA_ITEMS] =
> mediaItems;
>
> var activity = opensocial.newActivity(activityParams);
> opensocial.requestCreateActivity(activity,
> opensocial.CreateActivityPriority['HIGH']);
>
> Both seems correct but I couldn't find the problem. I want my app send
> notification and I want to display activity on users' profile.
>
> Any suggesstion would be appreciated. Please help if you have any
> idea.
>
> Thanks already.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"OpenSocial Application Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---