Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS 7上实现收藏夹推文功能_Ios_Objective C_Twitter_Slrequest_Acaccount - Fatal编程技术网

如何在iOS 7上实现收藏夹推文功能

如何在iOS 7上实现收藏夹推文功能,ios,objective-c,twitter,slrequest,acaccount,Ios,Objective C,Twitter,Slrequest,Acaccount,我正在iOS 7上使用 我想在我的应用程序中添加favorite函数。 为了获取用户流,我使用了STTwitter,然后我想要最喜欢的tweet。 但是STTwitter没有这样的功能,所以我决定使用account和SLRequest 我的编码如下所示,参考幻灯片88和89,但返回了状态代码400。 我怎样才能修好它?任何帮助都会大有帮助 - (IBAction)favButtonTouchDown:(id)sender { NSLog(@"Now trying to favorite twe

我正在iOS 7上使用

我想在我的应用程序中添加favorite函数。 为了获取用户流,我使用了STTwitter,然后我想要最喜欢的tweet。 但是STTwitter没有这样的功能,所以我决定使用account和SLRequest

我的编码如下所示,参考幻灯片88和89,但返回了状态代码400。 我怎样才能修好它?任何帮助都会大有帮助

- (IBAction)favButtonTouchDown:(id)sender {

NSLog(@"Now trying to favorite tweet id: %@", _tweetID);

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
_account = [accountStore accountWithIdentifier: ACAccountTypeIdentifierTwitter];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[accountStore requestAccessToAccountsWithType: accountType
                                      options: nil
                                   completion:^(BOOL granted, NSError *error) {
                                       if (granted)
                                       {
                                           NSArray *accounts = [accountStore accountsWithAccountType: accountType];
                                           if ([accounts count] > 0)
                                           {
                                               _account = accounts[0];
                                               _accountID = _account.identifier;
                                               NSLog(@"Getting account is OK. Account ID is: %@", _accountID);
                                           }
                                       } else {
                                           NSLog(@"Error while getting account.");
                                       }
                                   }];

NSString *urlString =
[NSString stringWithFormat:@"https://api.twitter.com/1.1/favorites/create.json?id=%@", _tweetID];
NSLog(@"URL will be: %@", urlString);

NSURL *url = [NSURL URLWithString: urlString];

// NSDictionary *params = @{@"trim_user" : @"1"};

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                        requestMethod:SLRequestMethodPOST
                                                  URL:url
                                           parameters:nil];

[request setAccount: _account];

UIApplication *application = [UIApplication sharedApplication];
application.networkActivityIndicatorVisible = YES;

[request performRequestWithHandler:^(NSData *responseData,
                                     NSHTTPURLResponse *urlResponse,
                                     NSError *error) {
    if (responseData) {

        NSString *httpErrorMessage = nil;

        if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {

            NSDictionary *postResponseData =
            [NSJSONSerialization JSONObjectWithData: responseData
                                            options: NSJSONReadingMutableContainers
                                              error: NULL];
            NSLog(@"SUCCESS! Added Favorite Tweet with ID: %@", postResponseData[@"id_str"]);

        } else {

            httpErrorMessage =
            [NSString stringWithFormat:@"The response status code is %ld",
             (long)urlResponse.statusCode];
            NSLog(@"HTTP Error: %@", httpErrorMessage);

        }

    } else {

        NSLog(@"ERROR: An error occured while posting %@", [error localizedDescription]);

    }

    dispatch_async(dispatch_get_main_queue(), ^{

        UIApplication *application = [UIApplication sharedApplication];
        application.networkActivityIndicatorVisible = NO;

    });

}];
}

谢谢。

STTwitter为大多数(如果不是所有的话)Twitter API端点提供了方法。将此用于收藏夹/创建端点。哦,这是我的错。。。谢谢你通知我。我会检查并重写代码:!