MGTwitterEngine Iphone oAuth - cocoa-touch

I hve try the MGTwitterEngine for oAuth from source https://github.com/kimptoc/MGTwitterEngine-1.0.8-OAuth
I am using this code for the MGTwitterEngine oAuth... but not working for me...
it give the same error I was getting in using xAuth without enabling xAuth Twitter integrated in Iphone App
Error Log is:
Twitter request failed! (3AFB8476-929F-4467-A4FE-DE43358CB62A) Error: The operation couldn’t be completed. (HTTP error 401.) ((null))
and one more thing I have not found anything in the for setting the application key and secret?
may be error due to this.. please help me.
Edited
Code on twitter button tab
-(IBAction)twitterBtnAct:(id)sender{
// Put your Twitter username and password here:
NSString *username = #"username";
NSString *password = #"password";
// Make sure you entered your login details before running this code... ;)
if ([username isEqualToString:#""] || [password isEqualToString:#""]) {
NSLog(#"You forgot to specify your username/password in AppController.m!");
}
// Create a TwitterEngine and set our login details.
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password];
// Get updates from people the authenticated user follows.
[twitterEngine getFollowedTimelineFor:username since:nil startingAtPage:0];
}
Amit Battan

HTTP 401 errors are about authentication problems. In the project, the application does:
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password]
Have you set this in your app?

I have use https://github.com/bengottlieb/Twitter-OAuth-iPhone for oAuth

Related

OSX ACAccountStore requestAccessToAccountsWithType... returning 'granted=No' and error=nil after denying permissions

I am trying to request access to my facebook account. The first time I ran this it went well and I saw the popup requesting permissions. The popup asked me to allow or deny. I chose to deny because I wanted to test that use case. Now I cannot figure out how to get it to allow access again. I have deleted the app from my facebook account and deleted my facebook account from my mac. I've also tried adding the property
#"auth_type": #"rerequest"
to the options dictionary. I get the same result no matter what.
As mentioned in the title, the error is nil and granted is False.
Thanks in advance.
ACAccountType* accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary* options = #{
ACFacebookAppIdKey: [[NSBundle mainBundle] objectForInfoDictionaryKey:#"FacebookAppID"],
ACFacebookPermissionsKey: #[#"public_profile", #"email", #"user_friends"],
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError* error)
{
if (granted)
{
ACAccount* account = [[accountStore accountsWithAccountType:accountType] lastObject];
macFacebookAccount = account;
}
else
{
NSLog(#"%#", error);
}
}];
I solved this: Facebook permission settings for an app are located under System Preferences > Security and Privacy. From there just click facebook and check the box next to your app

FBSDKLog: System authorization failed:

I have added facebook sdk for accessing the user account. But when user is already login in facebook via iOS 6 facebook then in my app on the very first page it must shows the alert that app is asking for profile permissions. For it I have added following code in app delegate
[FBSession openActiveSessionWithAllowLoginUI:true];
NSArray *permissions = [NSArray arrayWithObjects:
#"friends_about_me",nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (error) {
NSLog(#"Failure");
}
}];
return YES;
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL )url
sourceApplication: (NSString) sourceApplication annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
I am getting the alert properly.
But when I click on OK button it gives me following error
FBSDKLog: System authorization failed:'The Facebook server could not fulfill this access request: remote_app_id does not match stored id '. This may be caused by a mismatch between the bundle identifier and your app configuration on the server at developers.facebook.com/apps.
But in my fb developer account , everything is fine. Please help me in resolving this issue.
Thanks!
Are you sure you have the same bundle ID set in your Facebook app settings? A good way to validate is to use this code to print the bundle ID to the console and compare it with your app settings on Facebook:
NSLog(#"Bundle ID: %#",[[NSBundle mainBundle] bundleIdentifier]);
Dear Sudha may be your bundle id is not confirmed yet from all server of facebook. You have to wait for it.
Beware that your bundle ID is case sensitive!
I Faced the same issue when i run my project in 3.5 inch simulator it shows the same error. It works fine in 4 inch simulator. I fixed this issue by going to my 3.5 inch simulator settings then i logged out from my Facebook account. then i re run the project it worked.

objective-c : Twitter login error on iPad : Whoa there

I've been using the classic Ben Gottlieb Twitter Open Source project to create a twitter login for iPad.
My code to instantiate the engine and display the login controller is:
if (!_engine) {
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
[_engine setConsumerKey:#"kConsumerKey"];
[_engine setConsumerSecret:#"kConsumerSecret"];
}
if (![_engine isAuthorized]){
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller){
if ([controller respondsToSelector:#selector(setModalPresentationStyle:)] == YES) {
controller.modalPresentationStyle = UIModalPresentationFormSheet;
}
[self presentModalViewController:controller animated:YES];
return;
}
}
In addition, I set the URLS for SA_OAuthTwitterEngine to https:
self.requestTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://twitter.com/oauth/authorize"];
and my TWITTER_DOMAIN in MGTwitterEngine.m has been changed to:
#define TWITTER_DOMAIN #"api.twitter.com/1"
Running this code in the simulator for both iPhone and iPad works like a charm. HOWEVER, whenever I test this code on an iPad device, I'm thrown this error:
Whoa there! The request token for this page is invalid. It may have
already been used, or expired because it is too old. Please go back to
the site or application that sent you here and try again; it was
probably just a mistake
(Screenshot attached).
Any suggestions on how to get the standard login screen to appear will be greatly appreciated
I had the same problem and tried Jeff's way. It didn't work either. For some unknown reason, check your time settings and set to automatically set the time. This worked for me.
I ran into the same issue. What happens is that the request doesn’t get a request token. You can explicitly call that:
SA_OAuthTwitterEngine *myEngine;
[myEngine requestRequestToken];
Hope this helps!

Use twitter ios sdk oAuth

I try to use MGTwitterEngine for twitter Iphone integration,
this is supporting both xAuth and oAuth as per its documentation
and firstly I try it using xAuth as which function I am calling named getXAuthAccessTokenForUsername
But my application is in developing stage .. and twitter not approving it .. they will approve it after release...
I am not able to use oAuth using MGTwitterEngine
Can anybody help me...
Even I am not able to use oAuth version from source
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/comment-page-1/
I can update my status successfully using it...But not able do any thing else
I try
[_engine getUserInformationForEmail:#"battan20#gmail.com"];
//_engine is the twitterengine object
then getting error
Request 9EF8DE73-6E04-46F1-9D90-484F90FCA44F failed with error: Error Domain=HTTP Code=404 "The operation couldn’t be completed. (HTTP error 404.)"
Request 016DB024-1BFB-4E9B-8734-3FFCCB93D6E4 failed with error: Error Domain=HTTP Code=403 "The operation couldn’t be completed. (HTTP error 403.)"
Please help me
Amit Battan
When today I call
NSString *abc = [twitterObj getUserInformationFor:#"amit_battan"];
NSLog(#"abc...%#",abc);
Then I got the log
abc...F4BBA3C6-5783-46FF-A383-1B9C2319AB43
Request F4BBA3C6-5783-46FF-A383-1B9C2319AB43 succeeded
means it works ok...
But How I get the output.. in which function/variable
-(void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier {
NSMutableArray *mFollowerArray = nil;
mFollowerArray = [userInfo retain];
NSLog(#"count = %d",[mFollowerArray count]);
for (int i=0; i<[mFollowerArray count]; i++) {
NSLog(#" %#",[mFollowerArray objectAtIndex:i]);
}
}
above code might help

Objective C - Webkit external files causing 401

I'm currently using Webkit to display a mobile web on my iPhone app.
The domain is password protected, so I pass the username & password to the request.
It loads the main HTML page fine, however, even after passing the username & password, any other pages that the main HTML page loads (i.e css and js) are all returning 401.
Is there a way around that?
Thanks,
Tee
This is one of the use cases for ASIWebPageRequest.
If you want something lower level, you'll have to create an NSURLCredential instance and an NSURLProtectionSpace and save them to the credential store. At this point, the UIWebView should use the credential for all requests that match the protection space (which basically represents your site).
Here's some sample code, taken from here, which is not really where I'd expect to find it.
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser: #"userName"
password: #"password"
persistence: NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: #"www.mydomain.com"
port: 80
protocol: #"http"
realm: #"mydomain.com"
authenticationMethod: NSURLAuthenticationMethodDefault];
[[NSURLCredentialStorage sharedCredentialStorage]
setDefaultCredential: credential
forProtectionSpace: protectionSpace];
[credential release];
[protectionSpace release];
i think you need to pass the username and password in the css and js includes also...