Pergunta

Sou novato em programação, principalmente no lado da rede.Então agora estou criando um aplicativo para interagir com o Instagram.No meu projeto eu uso AFNetworking.Eu vi a documentação deles e muitos exemplos aqui.E ainda não entendo como obter a solicitação POST para a API do Instagram.Por favor, você poderia me dar um exemplo de código real ou algo onde eu possa ler sobre como fazer esta operação?Por favor ajude.Tentei fazer uma solicitação assim, não dá erros e nem resposta.Não dá 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!!");
}
Foi útil?

Solução

poucas coisas com que se preocupar.A API do Instagram retorna JSON para que você possa usar AFJSONRequestOperation que retornará um NSDictionary já analisado.
A API do Instagram diz que:

Todos os terminais são acessíveis apenas via HTTPS e estão localizados na api.instagram.com.

Você deve fazer uma alteração em seu URL 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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top