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:
Code:
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:
Code:
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?