Help with oAuth error message while connecting from an Appcelerator app.

381 views
Skip to first unread message

Peter Scheffer

unread,
Oct 27, 2011, 9:26:42 PM10/27/11
to stac...@googlegroups.com
Hi Guys,

I'm trying to get an Appcelerator app connected to the Stackmob REST API using oAuth.

I'm using this library - https://github.com/bytespider/jsOAuth, and the following code to connect.  I am getting an "Invalid OAuth credentials or signature" error message.

Any assistance is greatly appreciated.

var oauth = oauth.request({
  var oauth = new OAuth(options);

  method: "POST",
  headers: { 'Content-Type': 'application/json' }, 
  url: "http://mobiliser.mob1.stackmob.com/api/0/flirtwithme/message"
  data: '{"body":"just got auth working","sender":"pscheffer","recipient":"pscheffer"}',
  success: success,
  failure: failure
});


function success (data) {
  Titanium.API.info(data); 
  alert(data);
}


function failure (data) {
  Titanium.API.info(data); 
  alert(data);
}

Aaron Saunders

unread,
Oct 27, 2011, 9:33:19 PM10/27/11
to StackMob
I did not even bother, I wrote a native module for StackMob, should be
in the marketplace as soon as I understand what the availability will
be for others to get access to the platform. Would hate to sell a
module and then users not be able to access the platform.

If you post your code in a pastie or gist, I could take a look for you

On Oct 27, 9:26 pm, Peter Scheffer <peterfschef...@gmail.com> wrote:
> Hi Guys,
>
> I'm trying to get an Appcelerator app connected to the Stackmob REST API
> using oAuth.
>
> I'm using this library -https://github.com/bytespider/jsOAuth, and the

Peter Scheffer

unread,
Oct 27, 2011, 10:18:52 PM10/27/11
to stac...@googlegroups.com
Hi Aaron,

Will your native module integrate with Appcelerator code?  I'm still quite new to Appcelerator, but I'm happy with the turnaround time I'm getting with it.

Thankyou for offering to have a look at my code.  I've pasted it up to http://pastebin.com/ey6B7nks

The library it references can be downloaded from https://github.com/bytespider/jsOAuth

Again, any help would be greatly appreciated.

Thanks,
Peter.

Peter Scheffer

unread,
Oct 27, 2011, 10:19:42 PM10/27/11
to stac...@googlegroups.com
I have corrected this code.  Please see http://pastebin.com/ey6B7nks

Erick

unread,
Oct 28, 2011, 2:52:32 AM10/28/11
to stac...@googlegroups.com
Peter, again we don't support an official SDK yet, nor have we written one, but out of curiosity I wanted to try to help you out.  I fiddled around with jsOAuth tonight and this code works for me, though I did this in my browser and not Titanium.  I'm running Mac OSx Chrome and followed the jsOAuth testing instructions to get it running in my browser for testing:

"You can test in chrome using the following commandline on OSX /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --allow-file-access-from-files --allow-file-access --user-data-dir=~/chrome-test/ spec/runner.html"

I included this file:

<script type="text/javascript" src="jsOAuth-1.3.1.min.js"></script>

This is located on the jsOAuth GitHub page: (https://github.com/downloads/bytespider/jsOAuth/jsOAuth-1.3.1.min.js)

I do a GET and POST in the following code, and I get the correct JSON in return.  Change the URL and the keys to yours.

var oauth, options;

options = {
        //your keys can be found at https://www.stackmob.com/platform/account/apps/reset
consumerKey: 'this is your public key',  //replace this with your public key found in the link above
consumerSecret: 'this is your private key//replace this with your private key found in the link above
};

oauth = OAuth(options);

//getting a list of what's available in my API
console.debug(data);  //i'm using the chrome console to view the output
});

//posting a new user
oauth.request( {
method : 'POST',
headers: { 'Content-Type': 'application/json' },
data: '{ "username": "johnsmith", "password": "1234" }',
success: function(data) { console.debug(data); }, //again, using chrome console to view output
failure: function(data) { console.error('fail'); console.debug(data); } 
});

Erick

unread,
Oct 28, 2011, 3:22:23 AM10/28/11
to stac...@googlegroups.com
Peter, looking at your code, it looks like you're including a bunch of JS files for the Oauth.  Simply include the file I linked to above (jsOAuth-1.3.1.min.js).  

For completeness, here is WORKING code for your app (though in HTML).  I realized that you had your keys in the open so I just used them to GET/POST to your app.

<html>
<head>
<script type="text/javascript" src="jsOAuth-1.3.1.min.js"></script>
</head>
<body>

<script type="text/javascript">
/* <![CDATA[ */

var oauth, options;


options = {
consumerKey: '457c80ee-8d6d-40fa-8de2-61fcd315315b',
consumerSecret: 'f6f9da6b-8c5b-4fc9-bd41-7737f96b5ca1'
};

oauth = OAuth(options);

console.debug(data);
});

oauth.request( {
method : 'POST',
headers: { 'Content-Type': 'application/json' },
    data: '{"body":"hi peter this is erick","sender":"pscheffer","recipient":"pscheffer"}',
success: function(data) { console.debug(data); }, //again, using chrome console to view output
failure: function(data) { console.error('fail'); console.debug(data); } 
});

    
/* ]]> */
</script>
</body>
</html>

Erick

unread,
Oct 28, 2011, 4:08:59 AM10/28/11
to stac...@googlegroups.com
For future reference, here's a page with our Object querying formats:


You can find the URLs there which you want to mimic.

Peter Scheffer

unread,
Oct 30, 2011, 9:28:25 PM10/30/11
to stac...@googlegroups.com
Awesome, this is now working, thanks Erick.  

I'm not sure where the error lay, but switching to the production version (jsOAuth-1.3.1.min.js) of bytespider solved the issue.

Pete.

Erick Tai

unread,
Oct 31, 2011, 12:05:54 AM10/31/11
to stac...@googlegroups.com
Fantastic.  Glad to hear you're on your way!

Be sure to change your keys later since you don't want people using your keys to masquerade calls under your "name".

Rob Griffiths

unread,
Nov 14, 2011, 11:33:40 AM11/14/11
to StackMob
Peter,

I provide 2 versions of jsOAuth, one minified and the other not. I'd
love to know what problems you were encountering. By the sound of it
thought, you were including the individual files from the trunk repo
which may not always be in a state of completeness (sometimes I forget
and commit unfinished code to trunk).

Usually its best to download and include the lastest version of the
complete library. which can be found at http://cl.ly/3eyB

On Oct 31, 1:28 am, Peter Scheffer <peterfschef...@gmail.com> wrote:
> Awesome, this is now working, thanks Erick.
>
> I'm not sure where the error lay, but switching to the production version (
> jsOAuth-1.3.1.min.js) of bytespider solved the issue.
>
> Pete.

Erick

unread,
Nov 14, 2011, 1:57:03 PM11/14/11
to stac...@googlegroups.com
Rob, great work on the jsOAuth library.  We've had people fix their issues by switching out their existing OAuth js library and replacing it with yours - and that would fix it immediately.

Wanted to give you some props!
Reply all
Reply to author
Forward
0 new messages