Facebook上的图片上传连接iphone

时间:2011-03-02 07:24:44

标签: iphone image facebook upload

我是iphone应用程序开发的新手,我正试图通过我们的iphone应用程序在Facebook上传图像。我尝试过以下使用fbconnect的代码,但它无法正常工作。

NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:fbimages forKey:@"image"];    // 'fbimages'(it is having 2 images) is an array of 'UIImage' objects..
FBRequest *uploadPhotoRequest = [[[FBRequest alloc] init] autorelease];
uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:@"facebook.photos.upload" params:args];
//[[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:args];
NSLog(@"uploading image is successful");

5 个答案:

答案 0 :(得分:4)

最后,我发现了从iphone上传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];
}

获取此代码!!!!

YUVARAJ.M

答案 1 :(得分:1)

您需要为FBConnect使用FBSession和FBRequest代理的所有代理... 我刚从FBRequest委托调用了uploadPhoto方法。下面是我的代码...使用此代码...

- (void)request:(FBRequest*)request didLoad:(id)result {

    if ([[request method] isEqual:@"facebook.fql.query"]) {
        NSArray* users = result;
        NSLog(@"users %@",users);
        NSDictionary* user = [users objectAtIndex:0];
        NSLog(@"user %@",user);
        [self uploadPhoto];
    }
}

答案 2 :(得分:1)

我在这里回答了我的问题,即使用FBConnect进行Facebook图片上传。这是我自己的问题的正确答案。但是,现在我听说FBConnect在未来的移动应用程序Facebook连接中可能无效。所以,现在我更换了FBConnect的FBGraph API。那么,你们请省略FBConnect并尝试使用Graph API。它比FBConnect更容易。

答案 3 :(得分:1)

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Uploaded thru app",  @"message", nil];  
[params setObject:[UIImage imageNamed:@"image-name.png"] forKey:@"source"];
[facebook requestWithGraphPath:@"me/photos"
                     andParams: params
                 andHttpMethod: @"POST"
                   andDelegate:self];

答案 4 :(得分:-2)

快速注意一下 - 你应该试试ShareKit。它绝对令人惊叹,并且与社交媒体网站的所有互动都是轻而易举的。该库是开源的,易于扩展/可定制。

试一试,看看你的想法:

ShareKit home site