【问题标题】:Is it possible to give friend request on facebook using SLRequest in ios?是否可以在 ios 中使用 SLRequest 在 Facebook 上发出好友请求?
【发布时间】:2014-05-20 18:51:19
【问题描述】:
我正在使用SLRequest 获取用户详细信息并在 facebook 和 twitter 上分享。我还使用 Linkedin SDK 和 Google+ SDK 来获取各自社交网络上的用户详细信息。我的问题是
- 是否可以在 facebook 上使用
SLRequest 发送好友请求?
- 是否可以使用
SLRequest 在 Twitter 上关注某人?
- 是否可以使用 SDK 在linkedin 上连接一个人?
- 是否可以使用 SDK 在 google+ 上添加人员?
如果可能,请给我一个方法来做到这一点。谢谢。
【问题讨论】:
标签:
ios
objective-c
social-networking
【解决方案1】:
找了半天,找到了我的问题的解决办法,
Facebook graph api 2.0版本不支持好友请求(参考:https://developers.facebook.com/docs/dialogs/friends/v2.0)。
-
我们可以用 twitter 来做如下
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:@"MohammadMasudRa" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
NSLog(@"*******tempDict %@*******",tempDict);
//requestForServiceType
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i Error %d", [urlResponse statusCode],error.code];
NSLog(@"%@error %@", output,error.description);
}];
}
}
}];
-
我们可以使用 Linkedin 来做到这一点。
NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/mailbox"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setHTTPMethod:@"POST"];
NSString *messageToPerson = @"/people/email=test123@test.com";
NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,@"_path",@"test123",@"first-name",@"test",@"last-name",nil], @"person",nil];
NSArray *valueArray = [[NSArray alloc] initWithObjects:person,nil];
NSDictionary *values = [[NSDictionary alloc] initWithObjectsAndKeys:valueArray,@"values", nil];
NSDictionary *ir = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:@"friend",@"connect-type",nil], @"invitation-request",nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:values,@"recipients",@"Invitation",@"subject",@"ConnectWithMe",@"body", ir, @"item-content", nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *updateString = [update JSONString];
[request prepare];
[request setHTTPBodyWithString:updateString];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(postUpdateApiCallResult1:didFinish:)
didFailSelector:@selector(postUpdateApiCallResult1:didFail:) withPrepare:NO];
我无法通过 google plus add to circle 获取详细信息。