如何在Facebook墙上发布图像数据和网站URL

时间:2012-12-14 08:13:35

标签: iphone ios xcode facebook

任何人都可以解释我如何发布图像数据,这些数据将显示网站的图像和网址,点击我的Facebook墙上使用FBGraph api打开网站?

谢谢,

3 个答案:

答案 0 :(得分:3)

试试这个:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_url,@"source",image_url, @"link",nil];
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

答案 1 :(得分:2)

大家好,我现在可以使用social.framework将图像数据和网址一起发布。

请在项目中添加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];
}

答案 2 :(得分:1)

尝试通过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];
 }