Pregunta

Soy Newbie en la programación, especialmente en el lado de la red.Así que ahora estoy creando una aplicación para interactuar con Instagram.En mi proyecto uso AFnetworking.Vi su documentación y muchos ejemplos aquí.Y todavía no entiendo cómo obtener una solicitud de publicación a la API de Instagram.Por favor, ¿podría darme el ejemplo del código real o algo en el que puedo leer sobre cómo hacer esta operación?Por favor ayuda.Intenté hacer una solicitud como esta, no da errores ni respuesta.No da nada: (

(IBAction)doRequest:(id)sender{

NSURL *baseURL = [NSURL URLWithString:@"http://api.instagram.com/"];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient defaultValueForHeader:@"Accept"];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        user_token, @"access_token",
                        nil];

[httpClient postPath:@"/feed" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // reponseObject will hold the data returned by the server.
    NSLog(@"data: %@", responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error retrieving data: %@", error);
}];


NSLog(@"click!!");
}

¿Fue útil?

Solución

Pocas cosas a la que cuidar. API de Instagram devuelve a JSON para que pueda usar AfjsonRequestoperation, que devolverá un NSdicticario ya analizado.
La API de Instagram dice que:

Todos los puntos finales solo son accesibles a través de HTTPS y se encuentran en api.instagram.com.

Debe hacer un cambio a su base.

AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:yourURL];
NSURLRequest *request = [client requestWithMethod:@"POST"
                                             path:@"/your/path"
                                       parameters:yourParamsDictionary];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation
 JSONRequestOperationWithRequest:request
 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
    // Do something with JSON
}
 failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
    // 
}];

// you can either start your operation like this 
[operation start];

// or enqueue it in the client default operations queue.
[client enqueueHTTPRequestOperation:operation];

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top