Facebook Graph API - get a photos album ID

后端 未结 9 2165
小蘑菇
小蘑菇 2020-12-31 09:32

I\'m writing an application that uploads a photo to facebook. I\'m not supplying an album ID so an album is created on behalf of my app.

My question is: how do I get

相关标签:
9条回答
  • 2020-12-31 10:01

    This is the easy way to get it :

    0 讨论(0)
  • 2020-12-31 10:04
    String albumID = "https://www.facebook.com/photo.php?fbid=192570127478130&set=a.135556629846147.24342.100001754323389&type=1";
    albumID = albumID.split("&set=a.")[1];
    albumID = albumID.split("\\.")[0];
    System.out.println(albumID);
    
    0 讨论(0)
  • 2020-12-31 10:06

    This issue has been bugging me for a while as well, but I think I have cracked the nut.

    The album ID is hidden in the link value, so if you have a photo-post object from the Graph API, you can retrieve the Album ID like this:

    NSString *link = [item valueForKey:@"link"];
    NSString *album_id = nil;
    NSRange fRange = [link rangeOfString:@"set=a."];
    if(fRange.location != NSNotFound) {         
        NSInteger firstPos = fRange.location + 6;
        NSInteger endPos = [link rangeOfString:@"." options:NSLiteralSearch range:NSMakeRange(firstPos, 25)].location;
        album_id = [[link substringWithRange:NSMakeRange(firstPos, endPos - firstPos)] copy];
    }
    

    It could probably all be stripped down to one line of code, but I think this is more readable. For getting the album information use:

    [facebook requestWithGraphPath:album_id andDelegate:delegate];
    

    For getting all the photos in an album use:

    [facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/photos", album_id] andDelegate:delegate];
    

    Hope this can help someone.

    0 讨论(0)
提交回复
热议问题