AFNETWORKINGでの投稿要求
-
11-12-2019 - |
質問
プログラミングの初心者、特にネットワーク側ではありません。だから今私は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を返し、すでに解析されたNSDictionaryを返すAFJsonRequestOperationを使用できます。
Instagram APIはそのことを言う:
すべてのエンドポイントはHTTPS経由でのみアクセス可能で、 api.instagram.com。
あなたはあなたの基盤に変更を加えるべきです。
.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];
所属していません StackOverflow