iphone - 在 iPhone 的 Facebook 墙上分享图片和文字不起作用?

标签 iphone objective-c ios facebook

大家好,我想直接在 iphone 中分享图片和分享文字。 我在按钮点击时实现了以下代码,但它什么也没做...

     NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

 [variables setObject:[NSString stringWithFormat:@"Hi... Testing APp"] forKey:@"message"];
 [variables setObject:@"http://icon.png" forKey:@"picture"];       //http://tinyurl.com/45xy4kw
 [variables setObject:@"Create post" forKey:@"name"];
 [variables setObject:@"Write description." forKey:@"description"];

 [facebook requestWithGraphPath:@"/me/feed" andParams:variables andHttpMethod:@"POST" andDelegate:self]; 

我为此使用 facebook direct api Facebook API

最佳答案

使用这段代码工作正常

-(IBAction)postMeFeedButtonPressed:(id)sender {

    NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:8];


    //create a UIImage (you could use the picture album or camera too)
    UIImage *picture = [UIImage imageNamed:@"Icon@2x.png"];

    //create a FbGraphFile object insance and set the picture we wish to publish on it
    FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];

    //finally, set the FbGraphFileobject onto our variables dictionary....
    [variables setObject:graph_file forKey:@"file"];

    NSArray *idarry=[[NSArray alloc]initWithArray:Delegate.IdListArray];
    NSLog(@"Delegate array %@",Delegate.IdListArray);

    //NSString *str=[NSString stringWithFormat:@"100001912715296,100001912715296"];
    NSString *str=[idarry componentsJoinedByString:@","];

    NSLog(@"The string contents are %@",str);

   NSString *idstr=[NSString stringWithFormat:@"100002875785051,100001912715296"];

    [variables setObject:idstr forKey:@"tags"];
    [variables setObject:@"110506962309835" forKey:@"place"];

    [variables setObject:@"Hello All my dear friends,I am using MySafety APP" forKey:@"message"];
    [variables setObject:@"http://techilasolutions.com/product.html" forKey:@"link"];
    [variables setObject:@"My Safety" forKey:@"name"];
    [variables setObject:@"http://techilasolutions.com/images/car_tag.png" forKey:@"picture"];
    [variables setObject:@"This is a must have app for all women whether you are a working lady, a house wife or a school going girl.This app lets you save 6 emergency contacts whom you want to alert in case of emergency.Whenever you feel you are in danger, just press the SOS button and it will send sms to your contacts with your current location and a alarm will go on with flashing lights" forKey:@"description"];

    FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
    NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

    //parse our json
    SBJSON *parser = [[SBJSON alloc] init];
    NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
    [parser release];

    //let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
    self.feedPostId = (NSString *)[facebook_response objectForKey:@"id"];
    NSLog(@"feedPostId, %@", feedPostId);
    NSLog(@"Now log into Facebook and look at your profile...");

}

关于iphone - 在 iPhone 的 Facebook 墙上分享图片和文字不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480718/

相关文章:

iphone - 从我的 iPhone 应用程序将照片附加到电子邮件

iOS - 无法更改 View 原点

iOS 11 - 添加委托(delegate)后未收到位置更新

ios - Flutter ListView 双重弹跳问题

ios - 在通话或 Facetime session 中,尝试使用 SpeechRecognizer 会导致应用程序崩溃

iphone - 如何让内容在 Iphone 的 safari 或 android 的 webkit 的 DIV 中动态滚动?

ios - 如何在旧版本中创建Objective-C项目

iphone - 向 NSFetchedResultsController 添加额外的部分

iphone - iOS CocosDenshion 音频播放不均匀(滞后)

iOS7 新更新 V 7.1(11D167) 不兼容 Xcode 5 开发