2011-03-02 119 views
2

我是iphone應用程序開發新手,我試圖通過我們的iphone應用程序上傳Facebook上的圖片。我已經嘗試了使用fbconnect的下面的代碼,但它不起作用。圖片上傳在facebook上連接iphone

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"); 

回答

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

您需要使用FBSession和FBRequest代表所有代表FBConnect ... 我剛打電話從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]; 
    } 
} 
1

在這裏,我回答了我的問題,這是使用FBConnect的Facebook圖片上傳。這是我自己的問題的正確答案。但是,現在我聽說FBConnect可能無法在未來的Facebook移動應用連接中生效。所以,現在我換成了FBConnect的FBGraph API。所以,你們請忽略FBConnect並嘗試使用Graph API。它比FBConnect更容易。

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]; 
-2

只是一個快速的一面說明 - 你應該嘗試ShareKit。這絕對是令人驚歎的,並且使與社交媒體網站的所有互動變得輕而易舉。該庫是開源的,易於擴展/可定製。

試試吧,看看你的想法:

ShareKit home site