2012-11-25 51 views

回答

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

+0

謝謝,這很有幫助。 – NullSleep

+0

輕微更改,而不是TWRequest,現在您將使用SLRequest。 –

相關問題