如果您在计算机上将新闻分享到 Facebook,您可以选择分享“特定人员或列表”。
我只需要从我的 iOS 应用程序中为一些 friend 分享照片。
是否可以使用 Graph API 仅从应用程序中分享“特定人员或列表”的新闻?
Best Answer-推荐答案 strong>
使用社交框架在用户的墙上发帖
在 ACFacebookAudienceKey 中,选择其中一项
1.ACFacebookAudienceEveryone
2.ACFacebookAudienceFriends
3.ACFacebookAudienceOnlyMe
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSLog(@"0");
[accountStore requestAccessToAccountsWithType:accountType options{ACFacebookAppIdKey : @"00000000000", ACFacebookPermissionsKey : @"publish_stream", ACFacebookAudienceKey : ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
if(granted) {
NSLog(@"1");
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSLog(@"2");
if ([accountsArray count] > 0) {
NSLog(@"3");
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
NSLog(@"4");
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString"https://graph.facebook.com/me/feed"]
parameters:[NSDictionary dictionaryWithObject:post forKey"message"]];
NSLog(@"5");
[facebookRequest setAccount:facebookAccount];
NSLog(@"6");
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
}
}
}];
用于发布到 friend 的墙上。
- (IBAction)InviteActionid)sender // Button action
{
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle"Invite friends process cancelled"
message:nil
delegate:nil
cancelButtonTitle"OK"
otherButtonTitles:nil];
[alertView show];
} else if (session.isOpen) {
[self InviteAction:sender];
}
}];
return;
}
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"ick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentViewController:self.friendPickerController animated:YES completion:nil];
}
- (void) performPublishActionvoid (^)(void)) action
{
if ([FBSession.activeSession.permissions indexOfObject"publish_actions"] == NSNotFound)
{
[FBSession.activeSession requestNewPublishPermissions[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle"ermission denied"
message"Unable to get permission to post"
delegate:nil
cancelButtonTitle"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}
}
- (void)loginViewFetchedUserInfoFBLoginView *)loginView
userid<FBGraphUser>)user
{
self.loggedInUser = user;
}
- (void)facebookViewControllerDoneWasPressedid)sender
{
NSMutableString *text = [[NSMutableString alloc] init];
for (id<FBGraphUser> user in self.friendPickerController.selection)
{
if ([text length]) {
[text appendString:@","];
}
[text appendString:[NSString stringWithFormat:@"%@",user.id]];
}
//For post to friend's wall
NSDictionary *params = @{
@"name" : @"Hello Please checkout this app",
@"caption" : @" IOS APP",
@"description" : @"",
@"picture" : @"[email protected]",
@"link" : @"http:www.google.com",
@"to":text,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error publishing story.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to Post" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
} else {
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User canceled story publishing.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to post on your friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
} else {
NSLog(@"Story published.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Success" message:@"osted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
}
}}];
[self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"];
}
- (void)facebookViewControllerCancelWasPressedid)sender {
[self fillTextBoxAndDismiss:@"<Cancelled>"];
}
- (void)fillTextBoxAndDismissNSString *)text
{
[self dismissModalViewControllerAnimated:YES];
}
关于ios - Facebook:从 iOS 应用分享给特定的人或列表,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23102275/
|