How to implement twitter login functionality on iPhone - iphone

I've already tried to use Facebook login functionality. During the login I got user token and using this token I could identify user. So, Facebook is OK for me.
1) How can I implement login functionality with Twitter? Will I get anything the same like user token on Facebook?
As far as I know, to use twitter API user should be login in twitter in the settings of iPhone. Can I implement anything to enable user to login even he is not yet logged in in the settings of iPhone?
2) After user login I want him to invite his twitter friends to my application. Is it possible to do? And in what ways?
I will be grateful for some code examples.

Please check the link below each and every step is clearly told by Twitter itself.
https://dev.twitter.com/docs/ios
If you still having problem please follow the link
http://www.raywenderlich.com/5519/beginning-twitter-in-ios-5
That contains the code and all steps !
Hope it will help you !

Please go through this link
it will provide stepwise details.
add
#import <Twitter/Twitter.h>
Then you can tweet something using:
-(IBAction)tweetTapped:(id)sender {
{
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:
#"Tweeting from iOS 5 By Tutorials! :)"];
[self presentModalViewController:tweetSheet animated:YES];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure
your device has an internet connection and you have
at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}

Related

SLComposeViewController "Facebook not available"

I'm using the code snippet which was posted on my previous question, Simple way to add Facebook/Twitter share to app?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[slComposeViewController setInitialText:#"Your text"];
[slComposeViewController addImage:[UIImage imageNamed:#"NameOfImage"]];
[self presentViewController:slComposeViewController animated:YES completion:nil];
} else {
//Show alert or in some way handle the fact that the device does not support this //feature
NSLog(#"Facebook not available");
}
But when I run it on the device and in the simulator all I'm getting is "Facebook not available", what could I be doing wrong?
I've looked at the available tutorials, and I've included the libraries that are required, so I'm not sure what else I'm doing wrong.
In Settings.app/Facebook, you need to set up an account.
SLComposeViewController only allows you to posts on FaceBook if you have an account. That's normal behavior, that's how FaceBook works: No account, nothing to do there.
Since iOS6, you can enter your account in iOS allowing apps to use this account with some of the iOS framework without importing the Facebook SDK. Of course, you have little options with the Social.framework, and if you want to do more, like timelines, etc. you'll have to use the FaceBook SDK.

How do I post on friends' walls?

I am using the following code to post on device user's wall. I have managed to get the friends list and their ids too. Using the friend's id how can I use the following code to post on selected friend's wall depending on friend's id?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook ];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Posted!!!"
message:#"your status is posted to facebook successfully" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:#" hello there you got a text ..."];
[self presentViewController:controller animated:YES completion:Nil];
}
Take a look at the question Anton pointed you to. However, to my understanding, Facebook will be removing the ability to post to a friends wall using the Graph API in February 2013. Instead you will need to create a post by invoking the Feed Dialog and tagging friends in the post. The post will then appear on their wall (assuming they approve it). You'll want to keep this in mind as you decide how to go about this.
Posting to other users wall is as of February 6, 2013, deprecated.
https://developers.facebook.com/roadmap/completed-changes/
Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.
You can't post to friend's wall from API, But can be published to their Stream

How do I design and implement password authentication for IOS?

I have what seems to be a simple issue but I can't find a solution. I have spent hours trying to find an example that shows how to build a view, allow a user to enter a password, authenticate the password and return the view to a designated view. I have found a lot a great resources on bits and pieces, but they all are somewhat vague on how to authenticate the password and then send the user to a designated view.
This seems to be the best solution to my problem, which is: I have several pdfs that I need to password protect in my iPad app.
Issue1: Prompt for userName and Password
Present a view modally. if username/password combination is correct, dismiss the modal view. alternatively, you can use an alert with textfields.
Issue2: Store username/password in a secure way
Use key chain as suggested in the other answer. USage of key chain is as simple as using NSUserDefaults with Carlbrown's PDKeychainBindingsController. You can find it at the below link
https://github.com/carlbrown/PDKeychainBindingsController
EDITED to add info requested in comment:
Assuming you are using a custom view controller for login prompt, you have to do something like this when you want to prompt for password. it can be in your application didFinishLaunchingWithOptions.
LoginViewController *controller = [LoginViewController alloc];
[self presentModalViewController:controller animated:YES];
[controller release];
Then in your LoginViewController, you have to do something like this.
PDKeychainBindings *keyChain =[PDKeychainBindings sharedKeychainBindings];
if ([[keyChain objectForKey:#"User Name"] isEqualToString:userName] && [[keyChain objectForKey:#"Password"] isEqualToString:passWord] ) {
[self dismissModalViewControllerAnimated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ERROR" message:#"Wrong User Name and/or Password\nEnter Login Information Again"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
Please note that the strings userName and PassWord are captured from your textfields in login view controller.
In anticipation of your answer to my comment--
If you want the password to be stored locally, I would store it (hashed or otherwise) in the Keychain, to compare against the user-entered password. More in the Apple docs here.
I'd recommend downloading the Apple sample project for an example of storing/retrieving data from the keychain.
Oliver over at Cocoanetics.com has a very nice implementation of the security login screen apple uses. Look at the PinLockController class in MyAppSales.
https://github.com/Cocoanetics/MyAppSales
For keychain storage I use SFHFKeychainUtils. Its a simple method call to store and retrieve secure passwords. But I think standard NSUserDefaults would be sufficient for your needs.
(handy site http://gorgando.com/blog/tag/sfhfkeychainutils)
However, if you want to sell that app, keep in mind, that apple says
The user can set a four-digit personal identification number (PIN) to
prevent unauthorized use of the device, so there is no need for the
user to be authenticated and there are no authentication or
authorization APIs in iPhone OS.
This can be found in the Security Coding How-To's

How to give extended permissions in FBConnect with REST API in iPhone

I have developed an iPhone application, which is communicating data with faceBook. Initially I was only able to get basic information of user from Facebook. To post to a user's wall, I learnt about giving extended permission 'publish_stream', hence I added following code snippet:
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
[self getFacebookName];
}
And made necessary changes in the FBPermissiondialog class file.
Now this is allowing me to post to my wall, but it shows two separate dialogs for permissions, first to access user's basic information, and second for publishing permission. I want to have all permissions in a single pop-up. Also, I am using FBRequest to post to Facebook, not FBStreamDialog (as I dont want the UI for posting).
Please help me with this, I badly need to resolve this issue soon.
Thanks in advance.
In FBLoginDialog.m file
- (void)loadLoginPage {
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"1", #"fbconnect", #"touch", #"connect_display", _session.apiKey, #"api_key",
#"fbconnect://success", #"next",#"user_photos,photo_upload",#"req_perms",nil];
[self loadURL:kLoginURL method:#"GET" get:params post:nil];
}
add "req_perms" key to the dictionary as shown above.
Hope this will solve your problem :)

FBLoginDialog auto ask for Basic Permission before didLogin

I am using the old facebook iphone sdk to develop a iphone app: https://github.com/megastep/facebook-iphone-sdk
I am currently encountering a problem: The FBLoginDialog auto ask for Basic Permission before the didLogin callback.
I want to skip this part as I want to ask Exteneded permission.
And idea why facebook is asking the basic permission before the callback didLogin?
Thanks.
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
// dialog.delegate = self;
[dialog show];
You need to move to the new SDK. The SDK you are using is known to be buggy in several ways, it leaks memory and has problems on the 4.2 OS when the user is editing text and the keyboard is on screen.
Note also that the new SDK makes it extremely easy to ask for whatever permissions you need, you can just do it in the authorize:delegate method (see the sample project included in the sdk for an example).
Edit/Update:
Facebook asks for basic auth before didLogin because the user has to at least authorize your application.