0

我知道有很多关于 Twitter 集成和私人推文的信息。但我想知道如果我TWRequest在 ios7 中使用它会起作用吗?

My code snippet as follows.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
        if(granted)
        {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            // For the sake of brevity, we'll assume there is only one Twitter account present.
            // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

                NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
                [tempDict setValue:@"rohit40793982" forKey:@"screen_name"];
                //[tempDict setValue:@"true" forKey:@"follow"];
                // [tempDict setValue:@"683286" forKey:@"user_id "];

                TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://twitter.com/snehalikanksha/status/388535072359317504.json"]
                                                             parameters:tempDict
                                                          requestMethod:TWRequestMethodPOST];


                [postRequest setAccount:twitterAccount];

                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                {
                    NSLog(@"%@",urlResponse);
                    NSArray  *tweets = [NSJSONSerialization JSONObjectWithData:responseData
                                                                       options:kNilOptions
                                                                         error:&error];
                    NSLog(@"%@",tweets);
                    NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                    NSLog(@"%@", output);
                    [self performSelectorOnMainThread:@selector(displayText) withObject:output waitUntilDone:NO];

                }];
            }
        }
    }];

有谁能够帮助我 ?它给出Http错误 403。并且日志显示

"Your account may not be allowed to perform this action. Please <a class=\"js-reload\" href=\"#\">refresh the page</a> and try again."
4

1 回答 1

0

我不确定您要做什么,但您的代码不起作用的原因是您没有使用Twitter API端点。

如果您想获取特定推文的详细信息,可以使用GET statuses/show/:id

您将不得不更改您的代码:

NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/show.json?id=388535072359317504"];

TWRequest *request = [[TWRequest alloc] initWithURL:url
                                         parameters:nil
                                      requestMethod:TWRequestMethodGET];

STTwitter可以通过将每个端点映射到一个 Objective-C 方法来帮助您使用 API。

于 2013-10-26T17:26:50.220 回答