簡體   English   中英

將圖片上傳到Facebook連接iPhone

[英]image upload on facebook connect iphone

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

最后,我找到了從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

您需要使用FBSession的所有代理和FBConnect的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];
    }
}

在這里,我回答了我的問題,它使用FBConnect進行Facebook圖像上傳。 這是我自己的問題的正確答案。 但是,現在我聽說FBConnect在移動應用程序的將來Facebook連接中可能無效。 因此,現在已將FBGraph API替換為FBConnect。 因此,請忽略FBConnect並嘗試使用Graph API。 它比FBConnect更容易。

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

簡要說明一下-您應該嘗試使用ShareKit。 這絕對是驚人的,並且使與社交媒體網站的所有交互都變得輕而易舉。 該庫是開源的,可以輕松擴展/定制。

嘗試一下,看看您的想法:

ShareKit主頁

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM