MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Requesting Permission to Access Photos

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.

Published May 15 2008, 07:23 PM by Chris
Filed under: ,

Comments

 

Eddie said:

No advance warning again.

No easy way to tell 13,000+ users why their profile is now broken or how to fix it.

Another solution given that can only be used by some apps.

Ridiculous.

At least it looks like Flash apps don't have to go live blind now - though no one has said its fixed...

Better get on with changing my apps' white screen of death then...

Eddie

May 16, 2008 1:05 AM
 

Thomas said:

how can you get a permission using an external application?

May 16, 2008 10:24 AM
 

BeFunky said:

I agree Eddie...

May 17, 2008 3:10 AM
 

Eddie said:

Can we get an update please?

Eddie

May 19, 2008 12:11 AM
 

JC said:

I'm running up against this trying to create a flash app.  The flash library does not have the requestPermission method implemented.  I would appreciate any guidance on how to work around this.

June 5, 2008 9:37 PM
 

JC said:

Oh.  One other thing I'm confused about... In the screenshot above it shows that there are options to allow access to photos at the time of install.  I don't get these options when I install my app.  What circumstances are necessary to make these additional options appear at install time?

June 5, 2008 9:39 PM
 

Victor Corey said:

I am wondering as well how to get the options to allow access when the app is installed.

If I install the app then go to View My Apps and click on Settings for the app, I see the options, but not on install.

June 13, 2008 11:04 AM
 

Rich Goldman said:

It would be better to use opensocial.hasPermission() to test permissions rather than creating a request and checking if the response is null.

June 18, 2008 2:59 AM