Coder Social home page Coder Social logo

twittersdk's Introduction

TwitterSDK

CI Status Version License Platform

Demo App Screen Shot

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Set up

AppDelegate

#import "DemoAppDelegate.h"
#import <TwitterSDK/TwitterSDK.h>

NSString *const twitterConsumerkey = @"Your Consumer Key for Twitter API";
NSString *const twitterConsumerSecret = @"Your Consumer Secret for Twitter API";
NSString *const twitterOAuthCallbackURL = @"http://yourSiteDomain/oauth_callback";
NSString *const twitterRedirectURLString = @"yourAppScheme://authorize_complete";
NSString *const twitterServiceProviderName = @"yourServiceProviderName"; //ex twitterSDKDemoApp
NSString *const twitterPrefix = @"yourSiteDomain"; //ex twittersdkdemoapp.com

@implementation DemoAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[TwitterAppCenter defaultCenter] setUpWithKey:twitterConsumerkey
                                            secret:twitterConsumerSecret
                                 callbackURLString:twitterOAuthCallbackURL
                                  rediectURLString:twitterRedirectURLString
                               serviceProviderName:twitterServiceProviderName
                                            prefix:twitterPrefix];
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if ([[TwitterAppCenter defaultCenter] matchedURL:url])
        return [[TwitterAppCenter defaultCenter] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    
    return YES;
}

@end

Info.plist

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleTypeRole</key>
		<string>Editor</string>
		<key>CFBundleURLIconFile</key>
		<string></string>
		<key>CFBundleURLName</key>
		<string>mytwitter</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>twitterSDKDemoApp</string>
		</array>
	</dict>
</array>
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSExceptionDomains</key>
	<dict>
		<key>twimg.com</key>
		<dict>
			<key>NSIncludesSubdomains</key>
			<true/>
			<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
			<true/>
			<key>NSTemporaryExceptionMinimumTLSVersion</key>
			<string>TLSv1.1</string>
		</dict>
		<key>twitter.com</key>
		<dict>
			<key>NSIncludesSubdomains</key>
			<true/>
			<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
			<true/>
			<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
			<false/>
		</dict>
		<key>twittersdkdemoapp.com</key>
		<dict>
			<key>NSIncludesSubdomains</key>
			<true/>
			<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
			<true/>
			<key>NSTemporaryExceptionMinimumTLSVersion</key>
			<string>TLSv1.1</string>
		</dict>
	</dict>
</dict>

Example

@implementation DemoViewController
{
    __weak IBOutlet UITextView *textView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"TwitterSDK Demo";
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    if ([TwitterAppCenter defaultCenter].hasSession) {
        [self load];
    } else {
        [[TwitterAppCenter defaultCenter] loginWithCompletion:^(id result, NSError *error) {
            if (!error) {
                [self load];
            }
        }];
    }
}

- (void)load {
    NSString *path = @"https://api.twitter.com/1.1/statuses/home_timeline.json";
    NSDictionary *params = @{@"count": @"10",
                             @"user_id": [TwitterAppCenter defaultCenter].oauth.user.user_id,
                             @"screen_name": [TwitterAppCenter defaultCenter].oauth.user.screen_name};
    
    [[TwitterAppCenter defaultCenter] apiCallWithPath:path params:params completion:^(NSDictionary *result, NSError *error) {
        NSLog(@"result -> %@", result);
        textView.text = [NSString stringWithFormat:@"%@", result];
    }];
}

@end

Requirements

iOS Deployment Target 7.0 higher

Installation

TwitterSDK is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TwitterSDK"

Author

pisces, [email protected]

License

TwitterSDK is available under the MIT license. See the LICENSE file for more info.

twittersdk's People

Contributors

pisces avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.