我在编程中的新手,特别是在网络侧。所以现在我正在创建应用程序来与Instagram互动。在我的项目中,我使用afnetworking。我在这里看到了他们的文档和许多例子。我尚不理解,如何将发布请求发布到Instagram 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,因此您可以使用AfjsonRequestoperation,这将返回已经解析的NSDictionary。
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