gpt4 book ai didi

ios - Facebook:从 iOS 应用分享给特定的人或列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:23:53 25 4
gpt4 key购买 nike

如果您在计算机上将新闻分享到 Facebook,您可以选择为“特定的人或列表”分享。

我只需要从我的 iOS 应用分享照片给一些 friend 。

是否可以使用 Graph API 从应用中只为“特定的人或列表”分享新闻?

最佳答案

使用社交框架在用户墙上发帖

在 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)InviteAction:(id)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 = @"Pick Friends";
self.friendPickerController.delegate = self;
}

[self.friendPickerController loadData];
[self.friendPickerController clearSelection];

[self presentViewController:self.friendPickerController animated:YES completion:nil];
}

- (void) performPublishAction:(void (^)(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:@"Permission denied"
message:@"Unable to get permission to post"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}

}



- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
self.loggedInUser = user;
}


- (void)facebookViewControllerDoneWasPressed:(id)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" : @"logo@2x.png",
@"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:@"Posted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
}
}}];



[self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"];
}

- (void)facebookViewControllerCancelWasPressed:(id)sender {
[self fillTextBoxAndDismiss:@"<Cancelled>"];
}

- (void)fillTextBoxAndDismiss:(NSString *)text
{
[self dismissModalViewControllerAnimated:YES];
}

关于ios - Facebook:从 iOS 应用分享给特定的人或列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com