[英]How to share a link with image and description in facebook iPhone 6
UIImage *image = [UIImage imageNamed:@"attachment_blank.png"];
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImage:image userGenerated:NO];
NSDictionary *properties = @{
@"og:type": @"app:recipe",
@"og:title": @"Sample Recipe",
@"og:description": @"",
@"og:url": @"http://samples.ogp.me/216213502062059",
@"og:image": @[photo]
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
[shareAPI createOpenGraphObject:object];
The submission guidelines speak about a "user generated photos" permission that doesn't seem to be available anywhere in the app settings, or anywhere else in the documentation. 提交准则涉及“用户生成的照片”权限,该权限似乎在应用程序设置中的任何地方或文档中的其他任何地方都不可用。 Is that still required?
还需要吗? Is there a similar permission for images?
有类似的图片许可吗?
You can try this method to share an image with link. 您可以尝试使用此方法与链接共享图像。 The image you want to share should need to be on server(ie you need to use link of an image ) Note:- You must have an "publish_actions" permission from facebook app
您要共享的图像应该在服务器上(即,您需要使用图像的链接)注:-您必须具有facebook应用程序的“ publish_actions”权限
Below method is shown using the facebook sdk 4.3 使用facebook sdk 4.3显示以下方法
In .h file 在.h文件中
#import <FacebookSDK/FacebookSDK.h>
@property (strong, nonatomic) FBRequestConnection *requestConnection;
In .m file 在.m文件中
-(IBAction)facebookBtn:(id)sender{
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email", @"user_events", @"user_location", @"publish_actions"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", nil) message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
if (error.code!=2)
{
[alertView show];
}
}
else if (session.isOpen)
{
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self requestCompleted:connection forFbID:@"me" result:result error:error];
}];
// create the connection object
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request for fbid's profile
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:@"me" result:result error:error];
[self showAlert:NSLocalizedString(@"Posted successfully", nil)];
};
// create the request object, using the fbid as the graph path
// as an alternative the request* static methods of the FBRequest class could
// be used to fetch common requests, such as /me and /me/friends
NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ" ;
// Your facebook application link
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
}];
}
else
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request for fbid's profile
FBRequestHandler handler = ^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:@"me" result:result error:error];
[self showAlert:NSLocalizedString(@"Posted successfully", nil)];
};
// create the request object, using the fbid as the graph path
// as an alternative the request* static methods of the FBRequest class could
// be used to fetch common requests, such as /me and /me/friends
NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ";
// Your facebook application link
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.