如何在iOS 6中使用社交框架来关注Facebook页面/关注推特用户?

时间:2012-11-25 00:04:09

标签: facebook twitter ios6 facebook-like social

是否有一种简单的方法来喜欢Facebook页面/在iOS 6中使用社交框架关注Twitter用户?

我可以使用框架将消息发布到用户的Facebook / Twitter帐户。

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:3)

这是一种在Twitter上关注用户的方法

-(void)followTwitter{

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

[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
 {
     NSLog(@"this is the request of account ");
     if (granted==YES) {
         NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
         if ([arrayOfAccounts count] > 0)
         {
             // Keep it simple, use the first account available
             ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

             NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"FollowedUserNameHere",@"screen_name",@"TRUE",@"follow", nil];
             TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"] parameters:dictionary requestMethod:TWRequestMethodPOST];

             [request setAccount:acct];

             [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
              {
                  if ([urlResponse statusCode] == 200)
                  {
                      // The response from Twitter is in JSON format
                      // Move the response into a dictionary and print
                      NSError *error;
                      NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
                      NSLog(@"Twitter response: %@", dict);
                  }
                  else
                      NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
              }];
         }     
     }
 }];

}

并按照此链接获取喜欢的facebook页面

http://angelolloqui.blogspot.jp/2010/11/facebook-like-button-on-ios.html

答案 1 :(得分:0)

应该注意的是,从iOS 6.0开始,{@ 1}}被弃用,转而使用社交框架中的TWRequest,例如:Twitter SLRequest performRequestWithHandler - Could not prepare the URL request

上接受的答案