Getting Started

Obtain Application Key & Secret

Twitter requires that all API requests be authenticated with tokens that can be traced back to an individual Twitter App. If you already have keys for a Twitter app you can pass them directly to the Twitter.sharedInstance().start() method.

To create a new Twitter app or use existing Twitter app, visit Twitter apps dashboard and copy the keys from the “Keys and Access Tokens” tab of your app page.

To add call back URL:

  1. In Twitter apps dashboard, find your application and go to the permissions tab.
  2. Select the appropriate permissions for your needs (e.g. “Read and write”)
  3. If you are using login, add a placeholder URL in the Callback URL field (eg. “http://placeholder.com”).
  4. Click update settings.

Note

Although the callback URL will not be requested by Twitter Kit in your app, it must be set to a valid URL for the app to work with the SDK.

Getting app keys

Install Twitter Kit Using CocoaPods

To add Twitter Kit to your app, simply add the TwitterKit pod to your Podfile:

target 'MyApp' do
    use_frameworks!
        pod 'TwitterKit'
end

Then in your terminal run pod install, and finally pod update TwitterKit to make sure you have the latest version.

If you don’t have have CocoaPods set up for your app, you can run pod init from the root of your project directory.

Install Twitter Kit Manually

  1. Download and unzip Twitter Kit.
  2. Drag contents to the root of your project in Xcode
  3. Add TwitterKit to “Embedded Binaries” in your Xcode project settings
  4. Add TwitterKit and TwitterCore to “Linked Frameworks and Libraries” in your Xcode project settings

Note

Make sure ‘Copy items if needed’ is checked when prompted for options in Xcode.

Initialize Twitter Kit

Make sure to import the framework header: #import <TwitterKit/TwitterKit.h>

Note

If using Swift you will need to add it to your Objective-C bridging header

Inside your App Delegate, initialize Twitter Kit with your application key and secret (paste your own key and secret).

// Objective C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[Twitter sharedInstance] startWithConsumerKey:@"hTpkPVU4pThkM0" consumerSecret:@"ovEqziMzLpUOF163Qg2mj"];
}
// Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Twitter.sharedInstance().start(withConsumerKey:"hTpkPVU4pThkM0", consumerSecret:"ovEqziMzLpUOF163Qg2mj")

    return true
}

Configure Info.Plist

Twitter Kit looks for a URL scheme in the format twitterkit-<consumerKey>, where consumerKey is your application’s Twitter API key, e.g. twitterkit-dwLf79lNQfsJ.

You can find your consumer key in the Twitter app dashboard.

In your app’s Info.plist, add URL Schemes by adding code below after <dict>

// Info.plist
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>twitterkit-<consumerKey></string>
    </array>
  </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>twitter</string>
    <string>twitterauth</string>
</array>

Next Steps

Once Twitter Kit has been installed, see the following sections for further examples: