iOS 5 Twitter Framework: Tweeting without user input and confirmation (modal view controller)

前端 未结 4 1130
鱼传尺愫
鱼传尺愫 2020-11-27 17:18

Essentially what I want is for the app, once the user has allowed access to their Twitter account, to be able to tweet whatever the user has selected in a UITableView<

4条回答
  •  渐次进展
    2020-11-27 17:59

    Update: The TwitterKit in Fabric by Twitter is quite handy and if you aim to post from your Twitter app when the user tries to Tweet in your app then it might be a good option to consider.

    (YES, this method will allow you to post to twitter without any dialog box or confirmation).

    The TwitterKit will handle the permissions part and using the TWTRAPIClient we perform the tweet through the Twitter rest APIs.

     //Needs to performed once in order to get permissions from the user to post via your twitter app.
    [[Twitter sharedInstance]logInWithCompletion:^(TWTRSession *session, NSError *error) {
        //Session details can be obtained here
        //Get an instance of the TWTRAPIClient from the Twitter shared instance. (This is created using the credentials which was used to initialize twitter, the first time) 
        TWTRAPIClient *client = [[Twitter sharedInstance]APIClient];
    
        //Build the request that you want to launch using the API and the text to be tweeted.
        NSURLRequest *tweetRequest = [client URLRequestWithMethod:@"POST" URL:@"https://api.twitter.com/1.1/statuses/update.json" parameters:[NSDictionary dictionaryWithObjectsAndKeys:@"TEXT TO BE TWEETED", @"status", nil] error:&error];
    
       //Perform this whenever you need to perform the tweet (REST API call)
       [client sendTwitterRequest:tweetRequest completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
       //Check for the response and update UI according if necessary.            
       }];
    }];
    

    Hope this helps.

提交回复
热议问题