1

I used MGTwitterEngine

which try to login then request fail error comes

Error Detail

connectionIdentifier 6260FAFD-AE4E-4F05-AE67-FFA1DA18578F

error description The operation couldn’t be completed. (HTTP error 401.)

error user info ({ body = "\n\n Client application is not permitted to use xAuth.\n /oauth/access_token\n\n"; response = ""; })

Any Idea

-Amit Battan

Amit Battan
  • 2,968
  • 2
  • 32
  • 68

4 Answers4

3

Basic authentication is no longer supported by Twitter. You can use Twitter-oAuth-iPhone. It added oAuth with MGTwitterEngine. There is a demo code project included too. However, you will require SDK >= 3.2 to compile the latest version.

The problem with xAuth that you need to request to the Twitter API team providing detail of the application. In case of oAuth that is not required. You will need to create an application in Twitter Dev and then you need to use the keys in the project. That's all.

taskinoor
  • 45,586
  • 12
  • 116
  • 142
  • I tried the updated mgtwitterengine suggested by Matthew but it still give me the same error... and it is using oAuth.. means no issue with twitter enabled or disabled application key/secret ... – Amit Battan Dec 17 '10 at 11:56
  • I don't know about the one that you are talking, but I have used successfully the one I have suggested. May be you can share some code so that people can guess what is the problem. – taskinoor Dec 17 '10 at 15:12
  • BTW, if you are getting the same error that means you are using xAuth, not oAuth. For oAuth you don't need to request permission. – taskinoor Dec 17 '10 at 15:13
  • Have you created your app in Twitter Dev? If not then how you are using oAuth? Have you requested to the API team? If not then how you are using xAuth? – taskinoor Dec 17 '10 at 15:26
  • Hi have post the code..and I have already create app in twitter dev...and using oAuth even I haven't include files for xAuth – Amit Battan Dec 21 '10 at 05:40
  • yes I am calling getXAuthAccessTokenForUsername function.... I haven't more knowledge about xAuth and oAuth ...how we call oAuth..Should after releasing the application on appstore I have to implement xAuth?? – Amit Battan Dec 21 '10 at 06:56
  • @taskinoor Is MGTwitterEngine support oAuth or it only for xAuth – Amit Battan Mar 01 '11 at 13:08
  • @Amit Battan, as far as I know MGTwitterEngine itself is not updated to work with oAuth. But Twitter-oAuth-iPhone (the link I posted) added oAuth support to MGTwitterEngine. In case you need oAuth, you can try that. – taskinoor Mar 02 '11 at 05:54
  • ok.. if in future I need to switch it to xAuth after twitter approval then can I use same i.e Twitter-oAuth-iPhone – Amit Battan Mar 03 '11 at 04:32
  • but one more thing as in the MGTwitterEngine Document there are mention that use oAuthConsumer files for oAuth....and OAuthConsumer.h file is already imported in MGTwitterEngine.m file – Amit Battan Mar 03 '11 at 05:32
  • @taskinoor `OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"] consumer:consumer token:nil realm:nil signatureProvider:nil];` .............. as in the function getXAuthAccessTokenForUsername in class MGTwitterEngine class it call the https://api.twitter.com/oauth/access_token ..is it is **oAuth** – Amit Battan Mar 03 '11 at 05:39
1

MGTwitterEngine is significantly outdated at this point, as it doesn't use xAuth/oAuth. See this tutorial on using MGTwitterEngine with xAuth:

Switching from Basic to xAuth with mgtwitterengine on iPhone

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • well I have visited this link once..I thought that this is same MGTwiterEngine..but this is modified version...ok I am trying this and then get back – Amit Battan Dec 17 '10 at 07:13
  • I tried the updated mgtwitterengine suggested by Matthew but it still give me the same error... and it is using oAuth.. means no issue with twitter enabled or disabled application key/secret – Amit Battan Dec 17 '10 at 13:02
1

The OAuth do not need the permission from Twitter. But XAuth is required.

I'm not using MGTwitterEngine, with the official document of Twitter, I scratched a client with C, to calculated the nonce and signature, then use the tool cURL, then I can get the oauth_token and token_secret.

Additional message about cURL is that you must have created your App in Twitter, you can use the OAuth tool in your App(not required to be the current App your're working on) setting. If the App in twitter is not your current App, you should generate the cURL command line first. Set the Request Settings to POST and the Request URI to http://api.twitter.com/oauth/request_token, leave other setting as default, then click the button on the page bottom, you then see the cURL command, it seems like that:

curl --request 'POST' 'http://api.twitter.com/oauth/request_token' --header 'Authorization: OAuth oauth_consumer_key="your_consumer_key", oauth_nonce="your_random_string", oauth_signature="your_signature", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1329273306", oauth_token="451145411-AxGXG8xNdW1Eymwx85hs3sc1OE3NYsXe578AUtPe", oauth_version="1.0"' --verbose

replace the oauth_consumer_key , oauth_timestamp and oauth_signature with yours, delete the oauth_token and its value, copy the command to your cmd or shell and execute it. Another important trick is that, you must explicitly mark the oauth_callback in Authorization, and set the value as oob:

auth_callback="oob"

If your consumer_key and oauth_signature is correct, this steps will not lead to the Client application is not permitted to use xAuth error.

coanor
  • 3,746
  • 4
  • 50
  • 67
0

@taskinoor there the code I am using ... I have create application on twitter already

Controller .h file

#import <UIKit/UIKit.h>
#import "MGTwitterEngine.h"
@class OAToken;
@interface TwitterTestViewController : UIViewController <MGTwitterEngineDelegate> { 
    MGTwitterEngine *twitterEngine;
    OAToken *token;
}
@end

Controller .m file

#import "TwitterTestViewController.h"
@implementation TwitterTestViewController
- (void)awakeFromNib{
    // Put your Twitter username and password here:
    NSString *username = @"amit_bursys";
    NSString *password = @"mypassword";
    NSString *consumerKey = @"my_key";
    NSString *consumerSecret = @"my_seret";
    if (! username || ! password || !consumerKey || !consumerSecret) {
        NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!");
        NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection.");
    }
    twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
    [twitterEngine setUsesSecureConnection:NO];
    [twitterEngine setConsumerKey:consumerKey secret:consumerSecret];
    [twitterEngine setUsername:username];
    [twitterEngine getXAuthAccessTokenForUsername:username password:password];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
    [super dealloc];
}
#pragma mark MGTwitterEngineDelegate methods
- (void)requestSucceeded:(NSString *)connectionIdentifier{
    NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
}
- (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error{
    NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)", 
          connectionIdentifier, 
          [error localizedDescription], 
          [error userInfo]);
}
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier{
    NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
}
- (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier{
    NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
}
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
{
    NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
}
@end

and Code log is

2010-12-21 11:14:31.533 TwitterTest[734:207] Request failed for connectionIdentifier = D28BD476-7315-4510-B51A-968E516D169D, error = The operation couldn’t be completed. (HTTP error 401.) ({
    body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <request>/oauth/access_token</request>\n  <error>Client application is not permitted to use xAuth.</error>\n</hash>\n";
    response = "<NSHTTPURLResponse: 0x6022470>";
})
Amit Battan
  • 2,968
  • 2
  • 32
  • 68
  • You need to request xAuth permission directly from Twitter. It can't be done from twitter developer portal. [mentioned here](https://dev.twitter.com/docs/oauth/xauth) – JakubKnejzlik Nov 06 '11 at 00:50