문제

나는 프로그래밍 중, 특히 네트워크 측에서 초보자입니다.이제 Instagram과 상호 작용하는 앱을 만드는 것입니다.내 프로젝트에서는 Afnetworking을 사용합니다.나는 그들의 문서와 많은 예를 보았다.그리고 나는 아직 API를 인증하기 위해 게시물 요청을 얻는 방법을 이해하지 못합니다.이 작업을 수행하는 방법에 대해 읽을 수있는 실제 코드 예제 또는 무언가를 알려 주실 수 있습니까?도와주세요.나는 이런 식으로 요청하려고 노력했다. 그것은 오류가없고 응답이 없다.그것은 아무것도주지 않습니다 : ()

(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!!");
}
.

도움이 되었습니까?

해결책

걱정할 일이 거의 없습니다. Instagram API는 JSON을 반환하므로 이미 파싱 된 nsdictionary를 반환하는 afjsonrequestoperation을 사용할 수 있습니다.

Instagram API는 다음과 같습니다.

모든 엔드 포인트는 HTTPS를 통해서만 액세스 할 수 있으며 다음에 있습니다. api.instagram.com.

BaseURL을 변경해야합니다.

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];
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top