3

有没有一种简单的方法可以在 iOS 6 中使用社交框架来点赞 Facebook 页面/关注 Twitter 用户?

我可以使用该框架将消息发布到用户的 facebook/twitter 帐户。

非常感谢您的帮助!

4

2 回答 2

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

于 2012-11-27T09:26:16.947 回答
0

应该注意的是,从 iOS 6.0开始,社会框架TWRequest已弃用SLRequest,例如接受的答案:Twitter SLRequest performRequestWithHandler - 无法准备 URL 请求

于 2014-11-03T21:55:28.613 回答