PDA

View Full Version : Trying to port API call from jQuery to Sencha Touch



marzsman
4 Sep 2011, 11:30 AM
I developed an app in jQuery mobile that connects to an API with OAuth.
This works but I'm not completely happy with the performance and some functionality of the framework so I wanted to rebuild the same app in Sencha Touch.

The code I used to connect with the API in jQuery is this:


function oauthRequestToken() {
var accessor = { consumerSecret: $.consumerSecret
, tokenSecret: null };
var message = { action: $.apiUrl + 'oauth/request_token'
, method: 'GET'
, parameters: { oauth_consumer_key: $.consumerKey
, oauth_signature_method: $.signatureMethod }
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameters = OAuth.getParameterMap(message.parameters);
$.get(message.action, parameters, function(data) {
console.log(JSON.stringify(data));
});
}


I ported this function to Sencha like this:


function oauthRequestToken() {
var accessor = { consumerSecret: config.consumerSecret
, tokenSecret: null };
var message = { action: config.apiUrl + 'oauth/request_token'
, method: 'GET'
, parameters: { oauth_consumer_key: config.consumerKey
, oauth_signature_method: config.signatureMethod }
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameters = OAuth.getParameterMap(message.parameters);
Ext.Ajax.request({
url: message.action,
params: parameters,
method: 'GET',
success: function(response, opts) {
data = Ext.decode(response.responseText);

console.log(JSON.stringify(data));
}
});
}


It's almost exact the same code, except for the variables. The biggest difference is the "Ext.Ajax.request" call to the API.

The problem is that with the Sencha version I always get the error returned that my signature is not correct. I compared the 2 url's and I can't see any differences.

Can anyone tell me what I'm doing wrong? Do I have to use something else then Ext.Ajax.request to do a call to the API?

NCN
30 Apr 2012, 10:33 PM
Even I need to do the same.

have you completed your API call from the jqury to sench touch. If you completed the task.
Please share the code in zip file

Thahnk in advance. :)