ios - Facebook:从 iOS 应用分享给特定的人或列表
<p><p>如果您在计算机上将新闻分享到 Facebook,您可以选择分享“特定人员或列表”。</p>
<p>我只需要从我的 iOS 应用程序中为一些 friend 分享照片。</p>
<p>是否可以使用 Graph API 仅从应用程序中分享“特定人员或列表”的新闻?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用社交框架在用户的墙上发帖</p>
<p>在 ACFacebookAudienceKey 中,选择其中一项</p>
<p><strong>1.ACFacebookAudienceEveryone</strong></p>
<p><strong>2.ACFacebookAudienceFriends</strong></p>
<p><strong>3.ACFacebookAudienceOnlyMe</strong></p>
<p><code>ACAccountStore *accountStore = [ init];</code></p>
<p><code>ACAccountType *accountType = ;
NSLog(@"0");</code></p>
<pre><code>[accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey : @"00000000000", ACFacebookPermissionsKey : @"publish_stream", ACFacebookAudienceKey : ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
if(granted) {
NSLog(@"1");
NSArray *accountsArray = ;
NSLog(@"2");
if ( > 0) {
NSLog(@"3");
ACAccount *facebookAccount = ;
NSLog(@"4");
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:
parameters:];
NSLog(@"5");
;
NSLog(@"6");
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
NSLog(@"%@", [ initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
}
}
}];
</code></pre>
<p>用于发布到 friend 的墙上。</p>
<pre><code>- (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 = [ initWithTitle:@"Invite friends process cancelled"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
} else if (session.isOpen) {
;
}
}];
return;
}
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [ init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
;
;
;
}
- (void) performPublishAction:(void (^)(void)) action
{
if ( == NSNotFound)
{
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [ initWithTitle:@"Permission denied"
message:@"Unable to get permission to post"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
}
}];
} else {
action();
}
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
self.loggedInUser = user;
}
- (void)facebookViewControllerDoneWasPressed:(id)sender
{
NSMutableString *text = [ init];
for (id<FBGraphUser> user in self.friendPickerController.selection)
{
if () {
;
}
];
}
//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 = [initWithTitle:@"Failed" message:@"Failed to Post" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
;
} else {
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User canceled story publishing.");
UIAlertView *alertshow = [initWithTitle:@"Failed" message:@"Failed to post on your friend wall" delegate:NilcancelButtonTitle:@"ok" otherButtonTitles:nil];
;
} else {
NSLog(@"Story published.");
UIAlertView *alertshow = [initWithTitle:@"Success" message:@"Posted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
;
}
}}];
;
}
- (void)facebookViewControllerCancelWasPressed:(id)sender {
;
}
- (void)fillTextBoxAndDismiss:(NSString *)text
{
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Facebook:从 iOS 应用分享给特定的人或列表,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23102275/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23102275/
</a>
</p>
页:
[1]