Twitter login
This section explains how you can create an app with user registration using Twitter Login and Parse Server core features through Back4App.
To complete this quickstart, you need:
- An app created at Back4App.
- An iOS app connected to Back4App.
- Note: Follow the Install Parse SDK (ObjC) Tutorial to create an Xcode Project connected to Back4App.
To start using Twitter functions, you need to:
- Go to Twitter Application Management Website, sign in with a Twitter account and click on Create New App.
- Add your applicationās Twitter consumer key on your Parse applicationās settings page.
- When asked to specify a āCallback URLā for your Twitter app, please insert a valid URL likehttp://twitter-oauth.callback. This value will not be used by your iOS or Android application, but is necessary in order to enable authentication through Twitter.
- Add the Accounts.framework and Social.framework libraries to your Xcode project.
- Add the following where you initialize the Parse SDK, such as inapplication:didFinishLaunchingWithOptions:
ļ»æPFTwitterUtils provides a way to allow your PFUsers to log in or sign up through Twitter. This is accomplished using the logInWithBlock or logInWithTarget messages:
When this code is run, the following happens:
- The user is shown the Twitter login dialog.
- The user authenticates via Twitter, and your app receives a callback.
- Our SDK receives the Twitter data and saves it to a PFUser. If itās a new user based on the Twitter handle, then that user is created.
- Yourblock is called with the user.
If you want to associate an existing PFUser with a Twitter account, you can link it like so:
The steps that happen when linking are very similar to log in. The difference is that on successful login, the existing PFUser is updated with the Twitter information. Future logins via Twitter will now log the user into their existing account.
If you want to unlink Twitter from a user, simply do this:
Our SDK provides a straightforward way to sign your API HTTP requests to the Twitter REST API when your app has a Twitter-linked PFUser. To make a request through our API, you can use the PF_Twitter singleton provided by PFTwitterUtils:
ļ»æ