开发者

Twitter integration using oAuth error

Hello I have tried to post a tweet from my application. When I press on the button "post tweet" the authentication window (login window by twitter) opens, but when it is loaded my application just exits.

The following error occurs in the log;

[ERROR] Error Domain=com.google.GDataXML Code=-1 "The operation couldn’t be completed. (com.google.GDataXML error -1.)". in -[TiDOMDocumentProxy parseString:] (TiDOMDocumentProxy.m:50)

And in the end it says

 terminate called after throwing an instance of 'NSException

The code I used is:

var oAuthAdapter = new OAuthAdapter('SECRET KEY', 'KEY', 'HMAC-SHA1');


    // load the access token for the service (if previously saved)
    oAuthAdapter.loadAccessToken('twitter');

    oAuthAdapter.loadAccessToken('twitter');

    oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status', 'Tweet from appcelerator ' + Math.random()]], 'Twitter', 'Published.', 'Not published.');

    if (oAuthAdapter.isAuthorized() == false) {
        // this function will be called as soon as the applica开发者_开发问答tion is authorized 
        var receivePin = function(){
            // get the access token with the provided pin/oauth_verifier
            oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token');
            // save the access token
            oAuthAdapter.saveAccessToken('twitter');
        };
        // show the authorization UI and call back the receive PIN function 

        oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize' +
        oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token'), receivePin);
    }


Found the answer.

The line

 oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize'

Should be

 oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?'


Use This code instead of above two lines of showAuthorization and getRequestToken

oAuthAdapter.showAuthorizeUI('https://twitter.com/oauth/authorize?oauth_token=' +
oAuthAdapter.getRequestToken('https://twitter.com/oauth/request_token', 
[['oauth_callback', 'oob']]), receivePin, PinFinder.twitter);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜