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

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(){.sourceCode} 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{.sourceCode} pod to your Podfile:

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

Then in your terminal run pod install{.sourceCode}, and finally pod update TwitterKit{.sourceCode} 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{.sourceCode} 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

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>{.sourceCode}

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>{.sourceCode}, where consumerKey{.sourceCode} is your application's Twitter API key, e.g. twitterkit-dwLf79lNQfsJ{.sourceCode}.

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

In your app's Info.plist{.sourceCode}, add URL Schemes by adding code below after <dict>{.sourceCode}

// 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