MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Example Updating App Data

Last post 09-14-2008 8:48 PM by Fred Langemark. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 04-24-2008 3:42 AM

    Example Updating App Data

    Using the AS3Lib 

    import MyOpenSpace.*;
    import opensocial.*;

    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    var osToken:String = paramObj["opensocial_token"];
    var osSurfaceName:String = paramObj["opensocial_surface"];

    MySpaceContainer.instance.init(osToken, osSurfaceName);
                  
    var dr:MSDataRequest = opensocial.newDataRequest() as MyOpenSpace.MSDataRequest;

    dr.add(dr.newUpdatePersonAppDataRequest("VIEWER", "key", "color"), "appvar");
    dr.send(callback);

    function callback(dataResponse:DataResponse):void {
        txt.text = "done";
    }

    Gave me 

    <user xsi:schemaLocation="http://api.myspace.com/MySpaceAPI_1.1.xsd" xmlns="api-v1.myspace.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <userid>16329459</userid>

    <uri>http://api.msappspace.com/opensocial/v1/OWNER</uri>

    <appdata count="1">

    <key name="key" value="color"/>

    </appdata>

    </user>

    Now to figure out what the lib is doing to see if I can get something for AS2 to work...

    Eddie 

  • 04-24-2008 4:30 AM In reply to

    Re: Example Updating App Data

    AS3 outside the library:

    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    var opensocial_token:String = paramObj["opensocial_token"];
    var opensocial_surface:String = paramObj["opensocial_surface"];

    var url:String = "http://api.msappspace.com/opensocial/v1/VIEWER/appdata?opensocial_token=" + opensocial_token + "&opensocial_mode=" + opensocial_surface;

    var uRequest:URLRequest = new URLRequest();
    var uVariables:URLVariables = new URLVariables();

    uRequest.method = URLRequestMethod.POST;
    url += "&_method=" + "PUT"

    uRequest.url = url;

    uVariables["key2"] = "color2";
       
    uRequest.data = uVariables;
    uRequest.contentType = "application/x-www-form-urlencoded";

    uLoader = new URLLoader();
    uLoader.addEventListener(Event.COMPLETE, onComplete);
    uLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
    uLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);

    uLoader.load(uRequest);

    function removeEventListeners():void {
        uLoader.removeEventListener(Event.COMPLETE, onComplete);
        uLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
        uLoader.removeEventListener(IOErrorEvent.IO_ERROR, onError);           
    }

    function onComplete(event:Event):void {
        txt3.text = "done";
        removeEventListeners();
    }
    function onError(event:Event):void {
        txt3.text = "error";
        removeEventListeners();
    }

    Gives

    <user xsi:schemaLocation="http://api.myspace.com/MySpaceAPI_1.1.xsd" xmlns="api-v1.myspace.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <userid>16329459</userid>

    <uri>http://api.msappspace.com/opensocial/v1/OWNER</uri>

    <appdata count="2">

    <key name="key" value="color"/>

    <key name="key2" value="color2"/>

    </appdata>

    </user> 

    AS2 next?

    Eddie 

     

  • 04-24-2008 7:49 AM In reply to

    Re: Example Updating App Data

    Nice, looks like they just added a _method parameter we can use as a switch between setting ang getting data. I'll give it a try and see if it works in AS2. 

  • 04-24-2008 9:58 AM In reply to

    Re: Example Updating App Data

    Completely not my area of expertise here, but I noticed from the above that while both calls were to update '/v1/users/VIEWER/appdata', the returns give a URI for 'OWNER' ... Is that just how it always looks with Flash (again, not my area -- I've never used session-token-authentication with the MySpace REST services) ?

    Just curious.

  • 04-24-2008 10:28 AM In reply to

    Re: Example Updating App Data

    Sorry I didn't make it too clear did I (too excited).  

    The 'Give' / 'Gave me' was an xml load call of "http://api.msappspace.com/opensocial/v1/OWNER/appdata.xml?" + extension,

    running for the same test app but on a different surface to see if the app data had saved. I'd expect VIEWER to work as well, it was just how I had a call set up at the time.

    Eddie 

  • 04-24-2008 10:36 AM In reply to

    Re: Example Updating App Data

    It seems to be working for me using a token-based call. I'm using a LoadVars object to make the call and with the following request URL:

    http://api.msappspace.com/opensocial/v1/VIEWER/appdata.xml?opensocial_token=[user-token-here]&opensocial_mode=canvas&detailtype=BASIC&_method=PUT

    And, the variables I want to set applied to the LoadVars object, the request successfully sets user app data.

    Here's an example:

    function makePost(request:String, data:Object) {
      var send_lv:LoadVars = new LoadVars();
      for (var x:String in data) {
        send_lv.[x] = escape(data[x]);
      }
      send_lv.sendAndLoad(request,result_lv,"POST");
    }

    Where request is like the URL above and result_lv is another LoadVars object set to recieve onHTTPStatus and onData.

    I don't actaully get any data back on the onData response (just null), but I do get back an httpStatus code of 200. 

    When I try doing something similar using http://api.myspace.com/v1/ and OAuth, I get the following response:

    <error>
    <statuscode>400</statuscode>
    <message>Method Override not supported for method: GET </message>
    </error>

    So, I guess it's not set up on that REST domain. Maybe I'm not putting the _method= param in the right place, but that error message seems pretty specific.

    At least it's working for token-based calls and that's a good start. Thanks for tracking down that example Eddie.  

    ~Brock

    Filed under:
  • 04-24-2008 11:03 AM In reply to

    Re: Example Updating App Data

    Cheers Brock,

    Will hopefully use in the next couple of days when I get round to my AS2 apps. 

    Eddie 

  • 05-01-2008 12:25 AM In reply to

    • Dave
    • Top 25 Contributor
    • Joined on 02-04-2008
    • Posts 132

    Re: Example Updating App Data

    Eddie:

    AS3 outside the library:

    var url:String = "http://api.msappspace.com/opensocial/v1/VIEWER/appdata?opensocial_token=" + opensocial_token + "&opensocial_mode=" + opensocial_surface;

     

     

    Hi Eddie, I'm curious to know if you've tried setting data, from flash, for a user other than the VIEWER. 

    i.e. using REST: /v1/users/{userid}/appdata where userid might be the id of a friend of the viewer.

    The reason I ask is obviously using opensocial_token is different to OAuth, and I'm guessing we can set data for any user by using the secret key + oauth?  But we can't set any user data simply by using opensocial_token? Because it mirrors the javascript functionality which allows only setting data on the VIEWER.

    Anyway.. just curious if you've played around with app data for users other than viewer/owner.  Thanks!

  • 05-01-2008 1:21 AM In reply to

    Re: Example Updating App Data

    Hi Dave,

    I'm just a token man at the moment and didn't experiment further - was happy to get as far as I got and wanted to get customising colors etc into my apps asap.

    Just extremely frustrated I can't put the changes into a Live app at the moment....never mind the failure rates in my test app when getting and updating things.

    Getting I get around [most of the time] by recalling a number of times and not sure for updating whether to do the same or to get the users to 'try again'.

    Certainly at the moment it's not good to be a Flash app developer....

    Eddie 

     

  • 06-06-2008 9:18 AM In reply to

    • JC
    • Top 75 Contributor
    • Joined on 06-02-2008
    • Posts 41

    Re: Example Updating App Data

    Hi Dave,

     Were you ever able to figure out how to get info for users other than the VIEWER or OWNER?  I'm trying to figure out how to get photos of friends and what my limitations are.  If you have any insight I'd appreciate it.

     I'm even confused about this:  If I'm the only developer, and if myspace only allows apps to get photos of friends that have the app installed, then  how can I test this if none of my frends can install the app until it is public

     Maybe a stupid question, but I think I'm missing something.  My real hope would be that myspace doesn't limit me to only getting photos of friends that have the app installed.

  • 06-08-2008 10:55 PM In reply to

    • Dave
    • Top 25 Contributor
    • Joined on 02-04-2008
    • Posts 132

    Re: Example Updating App Data

    Hi JC, you can get a friends list using the REST api.  Take a look at this page: http://developer.myspace.com/community/RestfulAPIs/resources.aspx

    (I think..) the way to test your app is to add a couple of other developer accounts to your app. They could be dummy accounts you use for testing.  Once they are developers for the app they can also add it, even though it's not live yet.

    I forget what the rules are about getting photos of friends that don't have the app installed - if you need help with that then Eddie would know the answer..

  • 07-11-2008 12:41 PM In reply to

    App Data _method=PUT

    Brock:

    It seems to be working for me using a token-based call. I'm using a LoadVars object to make the call and with the following request URL:

    http://api.msappspace.com/opensocial/v1/VIEWER/appdata.xml
    ?opensocial_token=[user-token-here]&opensocial_mode=canvas&detailtype=BASIC
    &_method=PUT

    ... 

    When I try doing something similar using http://api.myspace.com/v1/ and OAuth, I get the following response:

    <error>
    <statuscode>400</statuscode>
    <message>Method Override not supported for method: GET </message>
    </error>

    So I'm getting the same error now when I send the request using the token-based process. Did Myspace remove that functionality? Seems that _method=PUT is no longer an option. Maybe it got broken in an update--or maybe it got changed to some other parameter. Anyone have any ideas?

    ~Brock

    Filed under:
  • 09-14-2008 8:48 PM In reply to

    Re: App Data _method=PUT

    If it possible to obtain an opensocial_token using a Friend ID?
Page 1 of 1 (13 items)