iOS で Facebook SDK を使用して新しいフォト アルバムを作成する必要があります。私のコードは機能していましたが、最近次のようなエラーを返し始めました:
{
"com.facebook.sdk:ErrorSessionKey" = "<FBSession: 0x7290850, state: FBSessionStateOpenTokenExtended, loginHandler: 0x7290c40, appID: 380841565285975, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x8a933e0>, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2013-10-14 03:16:01 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(\n \"create_note\",\n \"basic_info\",\n \"share_item\",\n \"status_update\",\n \"publish_actions\",\n \"video_upload\",\n email,\n \"photo_upload\",\n installed,\n \"publish_stream\",\n \"user_birthday\",\n \"user_location\"\n)>";
"com.facebook.sdk:HTTPStatusCode" = 500;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 2;
message = "An unexpected error has occurred. Please retry your request later.";
type = OAuthException;
};
};
code = 500;
};
}
https://developers.facebook.com/docs/reference/api/errors/によると、コード 2 のエラーは次のとおりです。
ただし、これは少なくとも数日間失敗しており、同様の問題を抱えている人を他に見つけることができないため、問題は私自身のものであると想定しています.
何が原因でしょうか?関連するコードは以下です。メソッドはcreateFacebookAlbum
失敗しているものです。
- (void)shareToFacebook {
if (FBSession.activeSession.isOpen) {
NSLog(@"SESSION IS OPEN");
[self createFacebookAlbum];
} else {
NSLog(@"SESSION IS NOT OPEN");
NSArray* permissions = [NSArray arrayWithObject:@"email"];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
if (error) {
/* handle failure */
NSLog(@"error:%@, %@", error, [error localizedDescription]);
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There was a problem with your Facebook permissions." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
else if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed ) {
[FBSession.activeSession closeAndClearTokenInformation];
}
else if (state == FBSessionStateOpenTokenExtended || state == FBSessionStateOpen) {
if(!self.presentedFacebookSheet) {
[self performSelector:@selector(reauthorizeAndContinuePostToFacebook) withObject:nil afterDelay:0.5];
self.presentedFacebookSheet = YES;
}
}
}];
}
}
- (void)reauthorizeAndContinuePostToFacebook {
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) {
[self shareToFacebook];
}];
}
- (void)createFacebookAlbum {
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
[parameters setObject:@"Test name" forKey:@"name"];
[parameters setObject:@"Test message" forKey:@"message"];
FBRequest* request = [FBRequest requestWithGraphPath:@"me/albums" parameters:parameters HTTPMethod:@"POST"];
NSLog(@"creating facebook album");
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:request
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString* albumId = [result objectForKey:@"id"];
NSLog(@"OK %@", albumId);
}
else {
NSLog(@"Error: %@",error.userInfo);
}
}];
[connection start];
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error {
switch (state) {
case FBSessionStateOpen:
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (error) {
//error
}
else {
NSLog(@"User session found");
}
}];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
}