MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

OS 0.8: fetch person treats Array.prototype function as requested PROFILE_DETAILS

Last post 03-12-2009 4:07 PM by Brendan. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-12-2009 3:52 PM

    OS 0.8: fetch person treats Array.prototype function as requested PROFILE_DETAILS

    • Summary

      If you use the Prototype javascript library, the execution of a newFetchPersonRequest created with PROFILE_DETAILS fails.  This happens because MyOpenSpace incorrectly views Prototype's Array extensions as requested fields.

    • Example (can be added via http://brendan.ilike.com/gadgets/myspace_test.xml)

      <script type="text/javascript" src="http://s1.ilike.com/js/prototype.js"></script>
      <script type="text/javascript">
      <!--
      function doIt() {
        var req = opensocial.newDataRequest();
        var params = {};
      
        // Ask for the profile url
        params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.PROFILE_URL];
      
        // Ask for the owner
        req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER, params), 'owner');
      
        var callback = function(response) {
          // process response
          var owner = response.get('owner');
      
          var responseEl = document.getElementById('response');
          responseEl.innerHTML = "global error? " + response.hadError() +
                                 "<br/>global error message: " + response.getErrorMessage() +
                                 "<br/>owner error? " + owner.hadError() +
                                 "<br/>owner error message: " + owner.getErrorMessage();
        };
      
        req.send(callback);
      }
      
      setTimeout(doIt, 500);
      // -->
      </script>
      <div id="response">No response received yet...</div>
    • Expected result

      Regardless of whether prototype.js is included, the response div should say that no errors occurred. This is a valid call.

       

    • Actual result

      If you include prototype.js, you'll receive the following error message:
      "Request contains not implemented fields:each, eachSlice, all, any, collect, detect, findAll, grep, include, inGroupsOf, inject, invoke, max, min, partition, pluck, reject, sortBy, toArray, zip, size, inspect, find, select, member, entries, _reverse, _each, clear, first, last, compact, flatten, without, uniq, intersect, clone, toJSON".

      These values are utility functions that Prototype adds to Javascript arrays. They should not be interpreted as requested fields for the PROFILE_DETAILS parameter.

      If you omit prototype.js, the call completes as expected.

    • Related

      There is another brief report of this issue with some workaround code. However, it involves monkey patching the MyOpenSpace javascript, which I'm sure is against the TOS and is qutie obviously prone to breaking.

      Instead of simply letting developeres work around this, MySpace should make sure the 0.8 code is compatible with Prototype. This works in 0.7.

  • 03-12-2009 4:07 PM In reply to

    Re: OS 0.8: fetch person treats Array.prototype function as requested PROFILE_DETAILS

    I'd suggest reading the Prototype Array documentation section entitled "Why you should stop using for...in to iterate" — it's a perfect description of what the container code is doing incorrectly.

Page 1 of 1 (2 items)