We recently introduced the ability for users to restrict applications from accessing either their public or private photos as you've probably noticed from the new install options (or if you're app can't get a user's photos anymore):
What if your app must have photos to be useful? You can use the opensocial.requestPermission() call to ask the user to allow access. Here's the UI when it's invoked:
Note that this will only work on the Canvas page. Here's a full sample of a simple app that uses and handles requestPermission properly:
function getPhotos() {
var personId = opensocial.DataRequest.PersonId.OWNER;
//Create our DataRequest object
var dr = opensocial.newDataRequest();
//Request Photos
var photoReq = dr.newFetchPhotosRequest(personId, {});
dr.add(photoReq,'Photos');
document.getElementById("output").innerHTML = "Requesting data...";
dr.send(response);
}
function checkPhotoPermissionResponse(result) {
if(result == null) {
//User clicked cancel
alert("We can't access your photos unless you let us :(");
}
else if(result["accesstopublicvideosphotos"]) {
//user checked the permission and clicked update
getPhotos();
}
else {
//User didn't check the permission
alert("We can't access your photos unless you let us :(");
}
}
function response(data)
{
document.getElementById("output").innerHTML = "Got response back";
if(data.hadError()) {
if(data.get("Photos").getErrorCode() == opensocial.ResponseItem.Error.UNAUTHORIZED) {
opensocial.requestPermission(["accesstopublicvideosphotos"], "Because we need your photos!", checkPhotoPermissionResponse);
}
}
else {
var photoMarkup = "";
var photos = data.get('Photos').getData();
photos.each(function(photo)
{
var imgUri = photo.getField(MyOpenSpace.Photo.Field.IMAGE_URI);
photoMarkup += "<img height='100' width='100' src='" + imgUri + "' />";
});
document.getElementById("photos").innerHTML = photoMarkup;
}
}
These are the official docs: http://developer.myspace.com/community/myspace/opensocialref.aspx#opensocial.requestPermission. The method takes an array of permission string values, a string to describe your reason for asking for permission that's displayed to the user, and a callback. The callback has one argument that is either is an object with each requested permission as a named property set to true/false depending on the user's input OR the argument will be set to null if the user cancelled the dialog. The permission string values for photos are "accesstopublicvideosphotos", "accesstoprivatevideosphotos" in addition to "displayonprofile", "displayonhome", "allowsendingemails" and "sendupdatestofriends".
The UI currently only supports one permission at a time, so if you want to access private and public photos, you will have to make two requests, but we plan to fix that shortly.