谁能解释我如何发布图像数据,以显示将使用 FBGraph api 在我的 Facebook 墙上单击打开网站的网站的图像和网址?
谢谢,
尝试这个 :
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_url,@"source",image_url, @"link",nil];
[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
大家好,现在我可以使用 social.framework 将图像数据和 url 一起发布。
请在您的项目中添加 social.framework 并使用 ios6 继续执行以下代码。
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"ResultCancelled");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"There might be some problem in facebook posting please try agian later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
} else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"We have checked in successfully on facebook." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Success");
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
[self uploadMessageToTwitter];
};
controller.completionHandler =myBlock;
[controller addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/social-checkin/id504791401?mt=8"]];
if (self.encoded_ImageData ==nil) {
[controller addImage:[UIImage imageNamed:@"No_ImageFound.png"]];
}
else
{
[controller addImage:[UIImage imageWithData:self.encoded_ImageData]];
}
NSString *businessName;
//Set business name string to be passed on facebook
if (m_BusinessNameString == nil || [m_BusinessNameString isEqualToString:@""])
{
businessName = @"Business name not specified!";
}
else
{
businessName = [m_BusinessNameString uppercaseString];
}
NSString *nameString = [NSString stringWithFormat:@"CHECKED IN @"];
//user has checked in with his friends if sc-merchant
NSString *friendsString;
if ([checkedFriendsNameArray count] > 0)
{
NSMutableString *checkedFriendsTempStr = [[NSMutableString alloc] init];
for (NSMutableString *checkedStr in checkedFriendsNameArray)
{
[checkedFriendsTempStr appendString:[NSString stringWithFormat:@"%@,",checkedStr]];
friendsString = [NSString stringWithFormat:@"WITH %@",checkedFriendsTempStr];
}
}
else
{
friendsString = [NSString stringWithFormat:@"WITH NO FRIENDS"];
}
NSString *fname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userfname"];
NSString *lname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userlname"];
NSString *name=[fname stringByAppendingString:[NSString stringWithFormat:@"%@",lname]];
NSString *main_TextString =[NSString stringWithFormat:@"%@ \n %@ %@ %@ %@",upperCaseStatusString,name,nameString,businessName,friendsString];
[controller setInitialText:main_TextString];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
NSLog(@"UnAvailable");
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
}
尝试像这样通过 fbgraph 发送图片:
- (IBAction)buttonClicked:(id)sender
{
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}
- (void)fbDidLogin
{
NSString *filePath =yourpathToImage;
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, yourpathToImage,
@"picture/jpeg", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}