【问题标题】:How can I post tweet to Twitter with Fabric framework without native composer? iOS如何在没有本地作曲家的情况下使用 Fabric 框架将推文发布到 Twitter? iOS
【发布时间】:2015-04-02 04:44:14
【问题描述】:

我集成了 Fabric 框架以在 iOS 平面表单上登录和发布推文。但我无法通过我的自定义文本视图发布推文。它总是显示 Twitter Composer。我怎样才能发布我的目的?谢谢!

这是我的代码:

    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:@""];
        }
    }];

【问题讨论】:

  • @MickyDuncan 请看我的版本。
  • @Dzung Le:你有解决方案吗?请分享我
  • @iOS_Ramesh 我收到了 Fabric 支持团队的邮件,目前 Fabric 不支持这个。

标签: ios twitter twitter-fabric


【解决方案1】:

试试这个:

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);
}

}];

【讨论】:

  • 第一行出现错误。 “Twitter”类型的值没有成员“APIClient”
  • 您确定与框架的集成有效吗?
  • 这里也一样,得到APIClient 错误。它说NO visible @interface for 'Twitter' declares the selector APIClient``。
【解决方案2】:

试试这个:

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)")
            }
        }
    }

必须先获取用户的userId。如果您使用手动按钮注册,请使用:

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)")
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 2014-12-10
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2018-10-21
    • 2018-10-01
    • 2017-02-22
    • 1970-01-01
    相关资源
    最近更新 更多