フェイスブックに写真をアップしています。写真の幅 > 高さの場合、すべて問題ありません。ただし、高さ > 幅の場合、Facebook は写真を上に表示するため、Facebook アカウントでは幅 > 高さで写真が表示されますが、(もちろん) 向きは間違っています。私のコード:
- (void)postImageToFaceBook:(UIImage *)imgSource
{
[self login];
currentAPICall = kAPIGraphUserPhotosPost;
NSString *strMessage = @"This is the photo caption";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imgSource,@"source",
strMessage,@"message",
nil];
NSLog(@"Begin sending photo\n\n");
[_facebook requestWithGraphPath:@"me/photos"
andParams:photosParams
andHttpMethod:@"POST"
andDelegate:self];
}
- (void)login
{
if (![_facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_photos",
nil];
[_facebook authorize:permissions];
[permissions release];
}
}
- (void)logout
{
[_facebook logout];
}
#pragma mark - FBRequestDelegate
- (void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@"Request load\n\n");
[self hideHud];
if ([result isKindOfClass:[NSArray class]] && ([result count] > 0)) {
result = [result objectAtIndex:0];
}
switch (currentAPICall) {
case kAPIGraphPhotoData: // step 3
{
NSLog(@"sending to wall\n\n");
// Facebook doesn't allow linking to images on fbcdn.net. So for now use default thumb stored on Picasa
NSString *thumbURL = kDefaultThumbURL;
NSString *imageLink = [NSString stringWithFormat:[result objectForKey:@"link"]];
currentAPICall = kDialogFeedUser;
NSMutableDictionary* dialogParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"app_id",
imageLink, @"link",
thumbURL, @"picture",
@"Photo from my iPhone application", @"name",
@"The app", @"caption",
@"it is fun to use", @"description",
nil];
[_facebook dialog:@"feed"
andParams:dialogParams
andDelegate:self];
break;
}
case kAPIGraphUserPhotosPost: // step 2
{
NSLog(@"getting data\n\n");
[self showHudWithMessage:@"Getting image data"];
NSString *imageID = [NSString stringWithFormat:[result objectForKey:@"id"]];
NSLog(@"id of uploaded screen image %@",imageID);
currentAPICall = kAPIGraphPhotoData;
[_facebook requestWithGraphPath:imageID
andDelegate:self];
break;
}
default:
break;
}
}
#pragma mark - FBDialogDelegate
- (void)dialogDidComplete:(FBDialog *)dialog {
switch (currentAPICall) {
case kDialogFeedUser:
{
NSLog(@"Feed published successfully.");
}
break;
default:
break;
}
}
postImageToFaceBook で、画像の幅が高さよりも小さいことを完全に確認するために画像サイズをチェックしました。幅は約2200、高さは3300、facebookのアルバム画像は幅>高さで表示されます。
前もって感謝します!