PFFacebookUtil Timeout Error - ios

I am having similar issue as mentioned here: https://www.parse.com/questions/error-when-trying-to-reauthorise-facebook-user
When my app starts up, if the user is already logged in it tries to fetch the user's profile image from Facebook:
- (void)getFacebookIdAndProfileImageWithSuccess:(void(^)(NSDictionary *))success {
// Send request to Facebook to retrieve profile information
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
return;
// Result is a dictionary of user information
NSMutableDictionary *userData = (NSMutableDictionary *)result;
NSString *facebookId = userData[#"id"];
[userData setObject:facebookId forKey:#"facebookId"];
// Retrieve the user profile image
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#/picture?height=55&width=55", BaseApiUrl, facebookId]];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];
[userData setObject:image forKey:#"image"];
[userData setObject:[imageUrl absoluteString] forKey:#"imageUrl"];
success([NSDictionary dictionaryWithDictionary:userData]);
}];
}
Well it takes a long time for the request to return and when it does it reports an error:
"Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x146aa790 {com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x146a1710 {NSErrorFailingURLStringKey=https://graph.facebook.com/,
NSErrorFailingURLKey=https://graph.facebook.com/, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1455c110 "The request timed out."}, com.facebook.sdk:HTTPStatusCode=200, com.facebook.sdk:ErrorSessionKey=<PFReceptionist: 0x14685310>}"

I deleted my app and installed it again. This resolved the issue. The problem might have been that before I started getting this error I was trying to resolve another Facebook related issue my app was having. And one of the things I tried was deleting my Facebook account Settings > Facebook. Maybe that had something to do with this error, I am not sure.

try this:
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info",#"email"] allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error){
if(error)
{
[self hideLoadingMode];
NSLog(#"Facebook Error : %#",error.localizedDescription);
// end you can use every thing you want
}
else{
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSlog(#"user ID %#",[user objectForKey:#"id"]);
}else{
[self hideLoadingMode];
}
}];
}
}
}];
i hope this help you

Related

iOS FacebookSDK Video Upload

I am trying to upload a video from my iOS app to Facebook and I am using the code:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"mp4"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mp4",
#"video/mp4", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/videos"
completionHandler:^(FBRequestConnection *connection,
id result, NSError *error)
{
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(#"SUCCESS RESULT: %#", result);
}
else
{
NSLog(#"ERROR: %#", error.localizedDescription);
}
}];
But I am getting the error:
FBSDKLog: Error for request to endpoint 'me/videos': An open FBSession must be specified for calls to this endpoint.
ERROR: The operation couldn’t be completed. (com.facebook.sdk error 5.)
Can any one please help me?
Log the access token to see if you have a valid one:
NSLog(#"AccessToken:%# ",FBSession.activeSession.accessTokenData.accessToken);
You need to be logged into your app via Facebook and need to have the publish_actions permission granted before you can make a POST request of any sort.
Once you have the access token, to quickly verify if it is valid and has the appropriate permissions, use the access token debugger.

facebook.sdk error 5 Objective-C

I'm a newbie in objective-c and I really need your help. I've been trying to solve this for hours now. And I still can't find a solution. Here is my codes:
-(void)post
{
[self connectWithFacebook];
NSLog(#"session: %hhd", FBSession.activeSession.isOpen);
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Here's to the Crazy Ones" ofType:#"mp4"];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *videoObject = #{
#"title": #"FB SDK 3.1",
#"description": #"hello there !",
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:#"me/videos"
parameters:videoObject
HTTPMethod:#"POST"];
NSLog(#"here i am");
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"after upload request");
if (!error)
NSLog(#"Done: %#", result);
else
NSLog(#"Error: %#", error.localizedDescription);
}];
}
AND
- (void) connectWithFacebook {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:YES];
}
And here's from the AppDelegate
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
NSArray *permissions = #[#"publish_stream"];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (error) {
NSLog (#"Handle error %#", error.localizedDescription);
} else {
NSLog(#"No error");
}
}];
}
Here's from the console:
2014-05-08 15:02:49.385 camera[3748:60b] Error: The operation couldn’t be completed. (com.facebook.sdk error 5.)
Your help will be greatly appreciated. Thank you. I really have no idea what to do next.
one possible error for com.facebook.sdk error 5 is
"This status update is identical to the last one you posted. Try
posting something different, or delete your previous update."

The operation couldn’t be completed. (com.facebook.sdk error 5.) FACEBOOK VIDEO UPLOAD

I wrote following code for uploading video to facebook from iOS device.
-(void)uploadVideo {
NSLog(#"UPload Videio ");
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"mov"];
NSLog(#"Path is %#", filePath);
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
// [facebook requestWithGraphPath:#"me/videos"
// andParams:params
// andHttpMethod:#"POST"
// andDelegate:self];
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"OK: %#", result);
} else
NSLog(#"Error: %#", error.localizedDescription);
}];
} else {
// We don't have an active session in this app, so lets open a new
// facebook session with the appropriate permissions!
// Firstly, construct a permission array.
// you can find more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
// In this example, we will just request a publish_stream which is required to publish status or photos.
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
//[self controlStatusUsable:NO];
// OPEN Session!
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// [FBRequestConnection setVideoMode:NO];
if(!error) {
NSLog(#"VEEERRRRRRR: %#", result);
} else
NSLog(#"VVEEERRRRREEEERRR: %#", error.localizedDescription);
}];
//[self promptUserWithAccountNameForUploadPhoto];
}
// [self controlStatusUsable:YES];
}];
}
}
This gives me error
The operation couldn’t be completed. (com.facebook.sdk error 5.)
I don't know what is wrong with facebook. It uploads image, text, but in video it gives this error.
NOTE:
It is not due to send again and again, as I also tested by making new account and resetting iOS Device.
sample.mov also exists and works with graph api, but issue is with this SDK.
Thanks.
Few causes for seeing com.facebook.sdk error 5:
Session is is not open. Validate.
Facebook has detected that you're spamming the system. Change video name.
Facebook has a defined limit using the SDK. Try a different app.
Wrong publish permission. Give publish_actions a spin.
more here... ?
Having read this solution. I was able solve this problem.
[FBRequestConnection startWithGraphPath:#"me/videos"
completionHandler:^(FBRequestConnection *connection,
id result, NSError *error)
{
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(#"SUCCESS RESULT: %#", result);
}
else
{
NSLog(#"ERROR: %#", error.localizedDescription);
}
}];
}];
I was having this problem all day when I noticed that my app does not appear in:
Settings App->Facebook->"ALLOW THESE APPS TO USE YOUR ACCOUNT"
This made me realize that posting to Facebook is not permitted by default, you must prompt the user for their permission:
[[FBSession activeSession] requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
// UPLOAD VIDEO HERE AND THAT ERROR 5 SHOULD GO AWAY
}
}];

Uploading video to Facebook from iOS app using SDK 3.6 intermittently failing

I'm using Facebook SDK 3.6 within an iOS 6.3 app to upload a video to Facebook.
I've looked over many Stack Overflow posts about this but they are all years old and using much older Facebook SDKs.
Sometimes it works, other times it fails with the following message:
unexpected error:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1e2affc0 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
body = {
"error_code" = 1;
"error_msg" = "An unknown error occurred";
};
code = 500;
}, com.facebook.sdk:ErrorSessionKey=, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2013-07-30 10:54:22 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
"publish_stream"
)>}
Here is my code:
FBRequestConnection *_currentConnection;
[FBSession.activeSession requestNewPublishPermissions:#[#"publish_stream"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
NSError *attributesError;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:&attributesError];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
NSLog(#"file size: %lld", fileSize);
NSString *filename = [url lastPathComponent];
NSLog(#"filename: %#", filename);
NSString *mimeType = [self MIMETypeForFilename:filename
defaultMIMEType:#"video/mp4"];
NSLog(#"mime type: %#", mimeType);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, filename,
mimeType, #"contentType",
self.song.name, #"title",
_videoDescription, #"description",
nil];
FBRequest *request = [FBRequest requestWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"];
_currentConnection = [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
self.stageLabel.text = #"";
NSLog(#"result: %#, error: %#", result, error);
if(error) {
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
[self showAlert:#"Video Post" result:result error:error];
}
self.uploadBarButtonItem.enabled = YES;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Video Uploaded" message:#"Video has been uploaded"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[self.delegate facebookUploaderUploadSucceeded:self];
}
// Delete the temp video
NSError *err;
[[NSFileManager defaultManager] removeItemAtURL:_sourceURL error:&err];
NSLog(#"Deleting video %#: %#", _sourceURL, [err localizedDescription]);
}];
}];
}
}];
This Code is Tested successfully On FaceBook SDK 3.14.1
-(void)shareOnFaceBook
{
//sample_video.mov is the name of file
NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:#"sample_video" ofType:#"mov"];
NSLog(#"Path Of Video is %#", filePathOfVideo);
NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
//you can use dataWithContentsOfURL if you have a Url of video file
//NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
//NSLog(#"data is :%#",videoData);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video name ", #"name",
#"description of Video", #"description",
nil];
if (FBSession.activeSession.isOpen)
{
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(#"RESULT: %#", result);
[self throwAlertWithTitle:#"Success" message:#"Video uploaded"];
}
else
{
NSLog(#"ERROR: %#", error.localizedDescription);
[self throwAlertWithTitle:#"Denied" message:#"Try Again"];
}
}];
}
else
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_actions",
nil];
// OPEN Session!
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (error)
{
NSLog(#"Login fail :%#",error);
}
else if (FB_ISSESSIONOPENWITHSTATE(status))
{
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
[self throwAlertWithTitle:#"Success" message:#"Video uploaded"];
NSLog(#"RESULT: %#", result);
}
else
{
[self throwAlertWithTitle:#"Denied" message:#"Try Again"];
NSLog(#"ERROR: %#", error.localizedDescription);
}
}];
}
}];
}
}
And I GOT Error:
The operation couldn’t be completed. (com.facebook.sdk error 5.)
It happens when facebook is being inited. Next time i open my app, it works fine, its always the first time. Tried everything in app, but it seems to be on the Facebook SDK side.
Few causes for seeing com.facebook.sdk error 5:
Session is is not open. Validate.
Facebook has detected that you're spamming the system. Change video name.
Facebook has a defined limit using the SDK. Try a different app.
Wrong publish permission. Give publish_actions a spin.

Error with uploading photo to facebook by Facebook iOS SDK 3.1.1

I'm developing an app and it allow user to upload their photo to facebook with message.
But it not work smoothly, sometime it works perfect, and it return this error many times.
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}
Here is my code
-(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];
}
Any one know how to fix this?
Thank you very much
You're seing timeouts from Facebook. See the description
NSLocalizedDescription=The request timed out.,
Your timeout setting is quite short. Facebook SDKs defaults timeout 180.
Since you're dealing with image upload 10 second may not always be enough. Set it higher to something like 30 seconds.

Resources