Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Installation

Rajul Arora edited this page Nov 14, 2017 · 17 revisions

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.

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 Using Carthage

To install TwitterKit for iOS using Carthage, add the following lines to your Cartfile. For more information about how to set up Carthage and your Cartfile, see here.

binary "https://ton.twimg.com/syndication/twitterkit/ios/TwitterKit.json"
binary "https://ton.twimg.com/syndication/twitterkit/ios/TwitterCore.json"

After running carthage update, add TwitterKit.framework and TwitterShareExtensionUI.framework to the Linked Frameworks and Binaries section under General of your App target. In addition to that, make sure that when you are adding the copy-frameworks run script for Carthage that you add the following input paths:

$(SRCROOT)/Carthage/Build/iOS/TwitterCore.framework
$(SRCROOT)/Carthage/Build/iOS/TwitterKit.framework
$(SRCROOT)/Carthage/Build/iOS/TwitterShareExtensionUI.framework

Make sure that the run script phase is after your Link Binaries with Libraries phase to prevent issues with properly archiving your iOS application.

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>

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:

  • log-in-with-twitter
  • compose-tweets
  • show-tweets
  • show-timelines
  • monetize-with-mopub
  • access-rest-api