Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you integrate the Parse Javascript API with Appcelerator and not use undocumented calls?

I would like to create a user from his/her Facebook credentials without using undocumented calls. I do not believe it is possible based on the current implementation of Parse Javascript Library for two known reasons:

1. The current implementation of the library does not support the Appcelerator HTTP client so it fails immediately. I have addressed this issue by extending the existing Parse Javascript library's ajax method to utilize the Appcelerator HTTP client.

http://www.clearlyinnovative.com/blog/post/34758524107/parse-appcelerator-titanium-the-easy-way

There has been approximately 2K views on the slide deck I created and about the same on the blog post, so it is pretty clear to me people want this to work.

2. The current implementation of the library assumes you are integrating with the Facebook Javascript library and that library does not work with Appcelerator either. In fact Appcelerator has integrated Facebook directly into the framework so there is no need for the javascript library. All of the information required to link a user account to Facebook can be easily gotten using the API calls that Appcelerator developers are already familiar with.

The original question was removed from the Parse Support forum so I am looking for a solution from a wider community.

Hi Aaron,

It's not helpful to other developers to promote using undocumented APIs in the Parse library as a workaround, so I make the decision to unlist it. I understand it might help in your particular case with Titanium, and you're well aware of the implications of using private APIs, but other users might overlook that warning. I hope you understand.

Héctor Ramos Solutions Architect, Parse https://parse.com/help

This is the code that was too dangerous to be left visible on the forum:

// setting auth data retrieved from Ti.Facebook login
authData = {
    "facebook" : {
        "id" : Ti.Facebook.uid,
         "access_token" : Ti.Facebook.accessToken,
         "expiration_date" : expDate, // "format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
    }
};

// Either way I resolved the problem, calling _handleSaveResult(true) on the returned user object, 
// I just dont think it should have been as difficult as it was
// attempt to log the user in using the FB information
var user = new Parse.User();
user.save({
    "authData" : authData
}).then(function(_user) {
    // force the user to become current
    _user._handleSaveResult(true); //<-- this is the evil method I called
    if (!_user.existed()) {

        // add additional user information
        var userInfo = {
            "acct_email" : "[email protected]",
            "acct_fname" : "Bryce",
            "acct_lname" : "Saunders"
        };
        return _user.save(userInfo);
    }
}).then(function(_user) {

    alert('Hooray! Let them use the app now.');

}, function(error) {
    alert(' ERROR: ' + JSON.stringify(error, null, 2));
});

Question on Appcelerator Forum

http://developer.appcelerator.com/question/152146/facebook-appcelerator-and-parse-integration-need-help

Question on Parse Forum

https://parse.com/questions/how-do-you-integrate-the-parse-javascript-api-with-appcelerator-and-not-use-undocumented-calls

like image 289
Aaron Saunders Avatar asked May 10 '13 11:05

Aaron Saunders


1 Answers

Maybe this part of a newer SDK, but can't you just call:

Parse.FacebookUtils.logIn({
  "facebook": {
    "id": "user's Facebook id number as a string",
    "access_token": "an authorized Facebook access token for the user",
    "expiration_date": "token expiration date of the format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
   },
   {
      success : function(_user) {},
      error : function(_user, error) {}
   }
};

It's not documented in the Javascript guide, but it is documented in the unminified version of the code visa vie:

@param {String, Object} permissions The permissions required for Facebook
log in.  This is a comma-separated string of permissions.
Alternatively, supply a Facebook authData object as described in our
REST API docs if you want to handle getting facebook auth tokens
yourself.

I made some updates to your original code to support the lastest SDK which I'm going to publish on Github.

Thanks so much for spearheading this effort. Your original post saved me hours.

like image 95
Andy Greenstreet Avatar answered Oct 07 '22 00:10

Andy Greenstreet