How can I tweet on Twitter using the Fabric framework without a native composer? IOS

I integrate the Fabric Framework to log in and send tweets in an iOS form. But I can not tweet by setting up textview. It always displays Twitter Composer. How can I publish for my purpose? Thank!

This is my code:

    TWTRComposer *composer = [[TWTRComposer alloc] init];

    [composer setText:textInput.text];
 // [composer setImage:[UIImage imageNamed:@"fabric"]];

    [composer showWithCompletion:^(TWTRComposerResult result) {
        if (result == TWTRComposerResultDone) {
            [Util showMessage:@"Post Tweet successfully!" withTitle:@""];
        }
        else {
            [Util showMessage:@"Unable to post Tweet" withTitle:@""];
        }
    }];
+4
source share
2 answers

Try the following:

TWTRAPIClient *client = [[Twitter sharedInstance] APIClient];
NSError *error;

NSString *url = @"https://api.twitter.com/1.1/statuses/update.json";
NSMutableDictionary *message = [[NSMutableDictionary alloc] initWithObjectsAndKeys:text,@"status", nil];

NSURLRequest *preparedRequest = [client URLRequestWithMethod:@"POST" URL:url parameters:message error:&error];

[client sendTwitterRequest:preparedRequest completion:^(NSURLResponse *urlResponse, NSData *responseData, NSError *error){

if(!error){
    NSError *jsonError;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
    NSLog(@"%@", json);
}else{
     NSLog(@"Error: %@", error);
}

}];
+2
source

Try the following:

func tweet(userId: String) {
        let client = TWTRAPIClient(userID: userId)

        let error: NSErrorPointer = NSErrorPointer()
        let url: String = "https://api.twitter.com/1.1/statuses/update.json"
        let message: [NSObject : AnyObject] = [
            "status" : "Sample Tweet Tweet!"
        ]

        let preparedRequest: NSURLRequest = client.URLRequestWithMethod("POST", URL: url, parameters: message, error: error)

        client.sendTwitterRequest(preparedRequest) { (response, data, jsonError) -> Void in
            do {
                let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! [String:AnyObject]
                NSLog("%@", json)
                print("Tweet post!")
            } catch {
                print("json error: \(error)")
            }
        }
    }

You must first get the userId of the user. If you use manual button registration, use this:

func tweet(userId: String) {
        let client = TWTRAPIClient(userID: userId)

        let error: NSErrorPointer = NSErrorPointer()
        let url: String = "https://api.twitter.com/1.1/statuses/update.json"
        let message: [NSObject : AnyObject] = [
            "status" : "Sample Tweet Tweet!"
        ]

        let preparedRequest: NSURLRequest = client.URLRequestWithMethod("POST", URL: url, parameters: message, error: error)

        client.sendTwitterRequest(preparedRequest) { (response, data, jsonError) -> Void in
            do {
                let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! [String:AnyObject]
                NSLog("%@", json)
                print("Tweet post!")
            } catch {
                print("json error: \(error)")
            }
        }
    }
+1
source

All Articles