gpt4 book ai didi

ios - 使用 Facebook iOS SDK 3.1.1 将照片上传到 Facebook 时出错

转载 作者:可可西里 更新时间:2023-11-01 06:11:17 25 4
gpt4 key购买 nike

我正在开发一个应用程序,它允许用户通过消息将他们的照片上传到 Facebook。但它运行起来并不顺利,有时运行完美,并且多次返回此错误。

2012-10-09 21:12:41.320 TimeLapse[1724:707] Error: HTTP status code: 200
2012-10-09 21:12:41.329 TimeLapse[1724:707] Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xf352290 {com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0xf351840 {NSErrorFailingURLStringKey=https://graph.facebook.com/me/photos?sdk=ios&access_token=.....&migration_bundle=fbsdk%3A20121003&message=Ghh&format=json, NSErrorFailingURLKey=https://graph.facebook.com/me/photos?sdk=ios&access_token=....&migration_bundle=fbsdk%3A20121003&message=Ghh&format=json, NSLocalizedDescription=The request timed out., NSUnderlyingError=0xf3518b0 "The request timed out."}, com.facebook.sdk:HTTPStatusCode=200}

这是我的代码

-(void)startPostPhotoToFacebook:(UIImage *)image withMessage:(NSString *)message {
NSArray *arrPermission = [NSArray arrayWithObjects:@"publish_stream", nil];

if (FBSession.activeSession.state == FBSessionStateOpen) {
NSLog(@"Session is opened already");
[self postPhotoToFacebook:image withMessage:message];
}
else {
NSLog(@"Need to open session");

[FBSession openActiveSessionWithPublishPermissions:arrPermission defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (!error) {
[self sessionStateChangedForPostPhotoToFacebook:session state:state error:error withImage:image andMessage:message];
}
else {
NSLog(@"Open active session failed");
}
}];
}
}

-(void)sessionStateChangedForPostPhotoToFacebook:(FBSession *)session state:(FBSessionState)state error:(NSError *)error withImage:(UIImage *)image andMessage:(NSString *)message {
switch (state) {
case FBSessionStateOpen: {
[self startPostPhotoToFacebook:image withMessage:message];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
default:
break;
}

if (error) {
NSLog(@"error");
}
}

-(void)postPhotoToFacebook:(UIImage *)image withMessage:(NSString *)message {
if (message == nil) {
message = @"";
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:message forKey:@"message"];

[params setObject:image forKey:@"source"];

FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"];

FBRequestConnection *fbConnection = [[FBRequestConnection alloc] initWithTimeout:10];
[fbConnection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"Result: %@", result);
[myMainViewController finishPostPhotoToFacebook];
[fbConnection release];
}
else {
NSLog(@"%@", error.description);
[myMainViewController errorPostPhotoToFacebook];
[fbConnection release];
}
}];

[fbConnection start];
}

有人知道怎么解决吗?非常感谢

最佳答案

您看到来自 Facebook 的超时。看说明

NSLocalizedDescription=The request timed out.,

您的超时设置很短。 Facebook SDK 默认超时 180。由于您正在处理图片上传,10 秒可能并不总是足够的。将其设置得更高一些,比如 30 秒。

关于ios - 使用 Facebook iOS SDK 3.1.1 将照片上传到 Facebook 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com