0

I'm trying to reading the pictures from my Facebook albums.

This is the code that I use for reading the albums:

- (void)storePhotoIntoCoreDataFromAlbumId:(NSString *)albumId whitAlbumName:(NSString *)albumName
{
    if (FBSession.activeSession.isOpen) {
        NSString *request = [NSString stringWithFormat:@"/%@/photos",albumId];
        [FBRequestConnection startWithGraphPath:request
                              completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                  if (!error) {
                                      if ([result isKindOfClass:[NSDictionary class]]) {
                                          if ([[result valueForKeyPath:@"data"] isKindOfClass:[NSArray class]]) {
                                              NSString *firstPageToRead = [result valueForKeyPath:@"paging.next"];
                                              [self storePicture:[result valueForKey:@"data"] withAlbumTitle:albumName];
                                              if (firstPageToRead) {
                                                  [self pagingQueryUntil:firstPageToRead];
                                              }

                                          }
                                      }
                                  } else {
                                      NSLog(@"Errore: %@", error);
                                  }
                              }
         ];
    }
}

This code works great, the problem it's inside the [pagingQueryUntil:firstPageToRead] method. I use this method in case there are a lot of pictures in the same album and I can't read it in one shot.

In this method I'm going to connect to the page to read the pictures in it:

- (void)pagingQueryUntil:(NSString *)until {
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            until, @"until",
                            nil];
    [FBRequestConnection startWithGraphPath:@"/me/photos"
                                 parameters:params
                                 HTTPMethod:@"GET"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {
 NSLog(@"Errore: %@", error);

}

And I got this error:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xd092be0 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            message = "(#100) Must be a unixtime or a date/time representation parseable by strtotime()";
            type = OAuthException;
        };
    };
    code = 400;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0xd089520, state: FBSessionStateOpen, loginHandler: 0x0, appID: 581914168536264, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xd1b0960>, expirationDate: 2014-07-19 08:35:28 +0000, refreshDate: 2014-05-20 08:36:52 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    "basic_info",
    "user_photos",
    installed,
    "user_location",
    "public_profile",
    email,
    "user_birthday",
    "user_friends",
    "friends_photos"
)>}

What's the problem?

Larme
  • 24,190
  • 6
  • 51
  • 81
Max_Power89
  • 1,710
  • 1
  • 21
  • 38
  • What are you passing as a value to `pagingQueryUntil`? – KerrM May 20 '14 at 10:24
  • i pass and url like this: https://graph.facebook.com/v1.0/10151580856822785/photos?access_token=CAAIRP3NOLMgBAOVeH8BjHqL2jh35auCZCKUdUt1hRpZCKohLaZCDJYcIcJGsEyxe4LK5gLowKrwIZAMCpd5MTtsVjUt8R.... if i open the url i got a list of pictures, so i think the url it's right – Max_Power89 May 21 '14 at 11:45
  • So, your variable `until` is "https://graph.facebook.com/v1.0/10151580856822785/photos?access_token=CAAIRP3NOLMgBAOVeH8BjHqL2jh35auCZCKUdUt1hRpZCKohLaZCDJYcIcJGsEyxe4LK5gLowKrwIZAMCpd5MTtsVjUt8R"? If that's the case then that's your problem, see my answer below. – KerrM May 21 '14 at 11:52

1 Answers1

0

I would venture that the string you are passing to pagingQueryUntil does not conform to one of the supported date and time formats outlined here. Because of this, the API is returning the error you see:

message = "(#100) Must be a unixtime or a date/time representation parseable by strtotime()";
KerrM
  • 5,139
  • 3
  • 35
  • 60
  • i tried to add 'date_format=U' like it's written in this post: http://stackoverflow.com/questions/10417868/convert-facebook-graph-api-date-to-unix-timestamp but i got the same error! – Max_Power89 May 21 '14 at 11:51
  • Log out the value of `until`. That value should conform to the date and time formats. If it doesn't then that's your problem. – KerrM May 21 '14 at 11:53