Get a specific image from any URL like Facebook does

后端 未结 1 790
独厮守ぢ
独厮守ぢ 2021-02-15 23:27

My Question might be looks like similar to other questions but really this is not.(according to my knowledge). i can\'t understand that how to fetch a specific image from any UR

相关标签:
1条回答
  • 2021-02-16 00:08

    finally, i got the answer. this might be helpful to you thats why i post this answer.
    use this macro
    #define FACEBOOK_GRAPH @"https://graph.facebook.com/v2.3/oauth/access_token?client_id=USE_YOUR_CLIENT_ID&client_secret=USE_YOUR_CLIENT_SECRET&grant_type=client_credentials"
    NOTE: you can get "client_id" and "client_secret" by registering your Application on developer.facebook.com
    now make a call for FACEBOOK_GRAPH Like bellow.

    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
        //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        manager.responseSerializer=[AFJSONResponseSerializer new];
        AFHTTPRequestOperation* operation = [manager POST:FACEBOOK_GRAPH parameters:nil
                                                  success:^(AFHTTPRequestOperation* op, id responseObject){
                                                      //here pass your URL as a string and access Token as a string, access token will found in responseObject
                                                  }
                                                  failure:^(AFHTTPRequestOperation* op, NSError* error){
                                                      NSLog(@"\n\nerror--->%@\n\n",error.localizedDescription);
                                                  }];
        [operation start];
    

    now the second method to get image from our URL, use our URL and access Token got from above method

    url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        token = [token stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
        AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer=[AFJSONResponseSerializer new];
        AFHTTPRequestOperation* operation = [manager POST:[NSString stringWithFormat:@"https://graph.facebook.com/v2.3/?id=%@&access_token=%@&scrape=true",url,token] parameters:nil success:^(AFHTTPRequestOperation* op, id responseObject){
            NSLog(@"\n\nData Response==\n%@\n",responseObject);
            //you will get Image URL in response
        }failure:^(AFHTTPRequestOperation* op, NSError* error){
                                                    NSLog(@"##error--->\n%@",error.localizedDescription);
                                             }];
        [operation start];
    
    0 讨论(0)
提交回复
热议问题