Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create photos album on Facebook sample code in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 285
    Comment on it

    Creating Photos album and uploading photos into the album. Two methods mentioned below creates album and uploads gallery pic on Facebook.

    /*=========================================================
     // Here we request connectin for creating album on facebook..
     ==========================================================*/
    NSMutableArray *image = [[NSMutableArray alloc]init];
     NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
     [parameters setObject:@"Ashish EventsApp" forKey:@"name"];
     [parameters setObject:@"Don't underestimate power of a common man!!!" forKey:@"message"];
     [parameters setObject:image forKey:@"picture"];
     self.postParams =
     [[NSMutableDictionary alloc] initWithObjectsAndKeys:
     image, @"picture", nil];
     [FBRequestConnection startWithGraphPath:@"me/albums" parameters:parameters HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
     FBGraphObject* temp = (FBGraphObject *)result;
     NSDictionary *dic=(NSDictionary*)temp;
     _strRequestId = [dic objectForKey:@"id"];
    
         if (error) {
             NSLog(@"%@", error.description);
         } else {
             NSLog(@"%@", result);
             _strRequestId = [dic objectForKey:@"id"];
             [self uploadImagesOnFB];
         }
     }];
    
    /*=========================================================
    

    Uploading Images to the album created from the above method.. ==========================================================*/

    -(void)uploadImagesOnFB{
    /*=========================================================
     In case of Uploading more than 1 Image in a album uncomment below code 
     ==========================================================*/
    /*UIImage *img1 = [UIImage imageNamed:@"Tajmahal.jpg"];
    UIImage *img2 = [UIImage imageNamed:@"2014.jpg"];
    UIImage *img3 = [UIImage imageNamed:@"eiffel.jpg"];
    image = [[NSMutableArray alloc]initWithObjects:img1,img2,img3, nil];
    self.postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[image objectAtIndex:_i], @"picture",nil];*/
    
    self.postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:image, @"picture",nil];
    [FBRequestConnection startWithGraphPath:[_strRequestId stringByAppendingString:@"/photos"]
                                 parameters:self.postParams
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error)
     {
         NSString *alertText;
         if (error) {
             alertText = [NSString stringWithFormat:
                          @"error: domain = %@, code = %d",
                          error.domain, error.code];
         } else {
             alertText = [NSString stringWithFormat:
                          @"Posted action, id: %@",
                          [result objectForKey:@"id"]];
             /*if (&#95;i<+image.count) {
                 _i++;
                 [self uploadImagesOnFB];
             }*/
         }
         // Show the result in an alert
         [[[UIAlertView alloc] initWithTitle:@"Result"
                                     message:alertText
                                    delegate:self
                           cancelButtonTitle:@"OK!"
                           otherButtonTitles:nil] show];
     }];
    

    }

    For more help see the attached code.

    Happy Coding...!!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: