iOs 8上的Twitter API有什么问题?

iOs 8上的Twitter API有什么问题?,ios,objective-c,twitter,Ios,Objective C,Twitter,我想在Objective-C中创建一个动作,在Twitter账户中即时“跟踪”,但当我启动我的应用程序时,它崩溃了。谁能告诉我怎么了 它返回线程1 exc\u bad\u access - (IBAction)Twitter:(id)sender { ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTyp

我想在Objective-C中创建一个动作,在Twitter账户中即时“跟踪”,但当我启动我的应用程序时,它崩溃了。谁能告诉我怎么了


它返回
线程1 exc\u bad\u access

- (IBAction)Twitter:(id)sender {

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

    [accountStore requestAccessToAccountsWithType:accountType options:nil
                                       completion:^(BOOL granted, NSError *error)  {
        if(granted) {

            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            if ([accountsArray count] > 0) {

                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

                NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
                [tempDict setValue:@"user" forKey:@"UserName"];
                [tempDict setValue:@"true" forKey:@"follow"];

                NSURL *URLTwitter = [NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.format"];

                SLRequest *postRequest = [SLRequest requestForServiceType:@"Twitter" requestMethod:SLRequestMethodPOST URL:URLTwitter parameters:tempDict];

                [postRequest setAccount:twitterAccount];

                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSString *output = [NSString stringWithFormat:@"HTTP response status: %li", [urlResponse statusCode]];
                    NSLog(@"%@", output);

                }];
            }
        }
    }];
}

您的twitter url不正确。应该是


https://api.twitter.com/1.1/friendships/create.json

这里是问题所在…
1.首先,由于新的Twitter API版本1.1,正确的URL是:
https://api.twitter.com/1.1/friendships/create.json

2.用户名的“for key”值必须是“screen_name”,它类似于以下片段:

NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"UserNameOnTwitter" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
  • “requestForServiceType”的值必须为SLServiceTypeTwitter,如下所示:

    SLRequest*postRequest=[SLRequest requestforservice类型:slservicetypeteetwitter请求方法:SLRequestMethodPOST URL:URLTwitter参数:tempDict]

  • 因此,整个街区将是:

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    
    [accountStore requestAccessToAccountsWithType:accountType options:nil
                                       completion:^(BOOL granted, NSError *error)  {
        if(granted) {
    
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
    
            if ([accountsArray count] > 0) {
    
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
    
                NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
                [tempDict setValue:@"UserNameOnTwitterWithoutAt" forKey:@"screen_name"];
                [tempDict setValue:@"true" forKey:@"follow"];
    
                NSURL *URLTwitter = [NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"];
    
                SLRequest *postRequest = [SLRequest requestForServiceType: SLServiceTypeTwitter  requestMethod:SLRequestMethodPOST URL:URLTwitter parameters:tempDict];
    
                [postRequest setAccount:twitterAccount];
    
                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSString *output = [NSString stringWithFormat:@"HTTP response status: %li", [urlResponse statusCode]];
                    NSLog(@"%@", output);
                }];
            }
        }
    }];
    

    谢谢大家。

    崩溃堆栈是什么?它返回
    线程1 exc\u bad\u access
    您需要在调试器中运行它。当它崩溃时,在调试器控制台中键入
    bt
    ,并将输出粘贴到此处。作为旁注…使用
    [tempDict setValue:@“user”forKey:@“UserName”]的任何原因
    而不是tempDict[@“user”]=@“UserName”
    ?@AshleyMills我认为这是一回事,不是吗?