как поделиться изображением на фейсбуке в iphone - PullRequest
0 голосов
/ 02 июля 2011

Я столкнулся с проблемой в моем коде. Я использую этот код:

//create a UIImage (you could use the picture album or camera too)

NSData *imageData = UIImageJPEGRepresentation(imgView.image, 8.0);
UIImage *picture = [UIImage imageWithData:imageData];

//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"];    
[variables setObject:@"i'm testing my iPhone App" 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...");

В этом коде я получаю сообщение об ошибке EXC_BAD_ACCESS, но изображение размещено в Facebook.

Как мне решить эту проблему?

Ответы [ 2 ]

3 голосов
/ 04 июня 2012
-(void)postInAppFacebook
{
    NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];
    UIImage *picture = FilterImage;
    FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
    [variables setObject:graph_file forKey:@"file"];
    [variables setObject:[NSString stringWithFormat:@"Hello testin"] forKey:@"message"];
    [fbGraph doGraphPost:@"me/photos" withPostVars:variables];
    NSLog(@"Now log into Facebook and look at your profile & photo albums...");

}
0 голосов
/ 02 июля 2011

Наконец-то я нашел решение для загрузки изображений на Facebook с. Используйте код ниже. Это будет работать точно.

- (void)uploadPhoto{
    NSMutableDictionary *args = [[NSMutableDictionary alloc] init];
    UIImage *img = [UIImage imageNamed:@"picture1.jpg"];
    NSData *data = UIImageJPEGRepresentation(img, 10);
    //NSData *data = UIImagePNGRepresentation(img);
    NSString *imgstr = [data base64Encoding];
    //NSString *imgstr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    //[args setObject:[UIImage imageNamed:@"antartica1.png"] forKey:@"image"];   
    [args setObject:imgstr forKey:@"image"];    // 'images' is an array of 'UIImage' objects
    uploadimgrequest = [FBRequest requestWithDelegate:self];
    [uploadimgrequest call:@"photos.upload" params:args dataParam:data];
    //[uploadimgrequest call:@"photos.upload" params:args];
}

получите этот код !!!!

или

для публикации изображения используйте следующий код (извлечено из демонстрационного приложения

- (IBAction) publishStream: (id)sender {

  SBJSON *jsonWriter = [[SBJSON new] autorelease];

  NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: 
                               @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];

  NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];

  NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"a long run", @"name",
                            @"The Facebook Running app", @"caption",
                            @"it is fun", @"description",
                            @"http://itsti.me/", @"href",
                            [NSArray arrayWithObjects:
                             [NSDictionary dictionaryWithObjectsAndKeys:
                              @"image", @"type",
                              @"http://www.gogle.com/", @"href",
                              @"http://a1.twimg.com/profile_images/457512510/iconoTwitter_bigger.gif", @"src",nil]
                             , nil ]
                            ,@"media", nil];


  NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 kAppId, @"api_key",
                                 @"Share on Facebook",  @"user_message_prompt",
                                 actionLinksStr, @"action_links",
                                 attachmentStr, @"attachment",
                                 nil];


  [_facebook dialog: @"stream.publish"
          andParams: params
        andDelegate:self];

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...