使用FBGraph API共享图像不起作用

时间:2012-08-21 13:13:01

标签: iphone facebook fb-graph

我使用下面的代码在fb wall上分享图片:

NSData *imageData = UIImageJPEGRepresentation(self.selectedImage, 10);
NSMutableDictionary* variables = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"your caption message", @"message", imageData, @"data", nil];
FbGraphResponse *fb_graph_response = [[sharedSingleton fbGraph] doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

但是当我尝试分享时,应用程序正在崩溃。 指导我解决这个问题

2 个答案:

答案 0 :(得分:4)

尝试此代码.....

- (IBAction)postPictureButtonPressed:(id)sender {

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];

//create a UIImage (you could use the picture album or camera too)
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 240, 240)];
[imgView setImage:[UIImage imageNamed:@"app1.jpg"]];
[self.view addSubview:imgView];
[imgView release];


UIImage *tempimag=imgView.image;

//UIImage *picture = [UIImage imageNamed:@"75x75.png"];

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

NSLog(@"img posted");


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

[variables setObject:@"this is a test message: postPictureButtonPressed" forKey:@"message"];

//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"117795728310/photos" withPostVars:variables];
NSLog(@"postPictureButtonPressed:  %@", fb_graph_response.htmlResponse);


NSLog(@"Now log into Facebook and look at your profile & photo albums...");

}

答案 1 :(得分:0)

// JSON示例

.H FILE

NSMutableArray * arrRespone;

NSMutableDictionary *resultsDictionary;

.M FILE

define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)// 1

定义kLatestKivaLoansURL [NSURL URLWithString:@" http://www.indiaglitz.com/json/vod_menu_init.asp"]

// how can print array json values into uitableview in iphone

import" ViewController.h"

@interface ViewController()

@end

@implementation ViewController

@synthesize tableView1;

  • (无效)viewDidLoad中

{

arrRespone = [NSMutableArray new];

practice_ArrayForDisplayingEx=[[NSArray alloc]initWithObjects:@"bhupi",@"bhupi",@"bhupi",@"bhupi",nil];


dispatch_async(kBgQueue, ^

{

NSData * dataURL = [NSData dataWithContentsOfURL:kLatestKivaLoansURL];         [self performSelectorOnMainThread:@selector(fetchedData :) withObject:dataURL waitUntilDone:YES];     });

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

  • (void)fetchedData:(NSData *)responseData {

    NSError *错误;

    resultsDictionary = [NSJSONSerialization JSONObjectWithData:responseData // 1                                                     选项:kNilOptions                                                       误差:&安培;错误];

    NSDictionary * arrDetails = [[resultsDictionary objectForKey:@" menu"] objectAtIndex:0]; NSDictionary * genr = [[arrDetails valueForKey:@" categories"] objectAtIndex:0];

    NSLog(@" array detailsarray ====>%@",arrDetails); NSLog(@" genreee arrray ==%@",genr); // NSLog(@" genrvalueeee -----%@",[genr valueForKey:@" genre"]);

    NSLog(@" counttttt ===%d",[[genr valueForKey:@" genre"] count]); NSLog(@"流派objectatindex ==%@",[genr valueForKey:@" cliptype"]);

    for(int i = 0; i< [[genr valueForKey:@" genre"] count]; i ++) {

    NSDictionary *strDetails=[[genr valueForKey:@"genre"] objectAtIndex:i];
    NSString *str=[strDetails valueForKey:@"gname"];
    NSLog(@"First string details===>%@",str);
    
    
    [arrRespone addObject:str];
    
    NSLog(@"response ====>%@",arrRespone);
    

    } [tableView1 reloadData]; }

pragma mark表视图方法

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    的NSLog(@" numberOfSectionsInTableView&#34);

    返回1; }

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 返回45;

    的NSLog(@" heightForRowAtIndexPath&#34);

}

//自定义表视图中的行数。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {     的NSLog(@" numberOfRowsInSection&#34);

return [arrRespone count]; }

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"在tableview内部"); static NSString * CellIdentifier = @" TableCell&#34 ;;

    // TableCell * cell =(TableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){

    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
    

    } // cell.textLabel.text = [arrRespone objectAtIndex:indexPath.row];

    的NSLog(@" cellvalue:%@",cell.textLabel.text); NSLog(@"在numberofRowsInsection"内;); //配置单元格......   cell.textLabel.text = [arrRespone objectAtIndex:indexPath.row];

    返回单元格;

}

  • (无效)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; //处理可以重新创建的任何资源。 }

@end