title: AFNetworking 2.0 and authorizing the Imgur API
body: <p><a href="http://api.imgur.com/" rel="nofollow">Imgur's API</a> requires that for simply looking up information about an image you just need to authorize your app with your API keys, no need to log in with an account or anything.</p>
  
  <p>It says:</p>
  
  <blockquote>
    <p>...all you need to do is send an authorization header with your client_id in your requests</p>
  </blockquote>
  
  <p>Which apparently looks like:</p>
  
  <p><code>Authorization: Client-ID YOUR_CLIENT_ID</code></p>
  
  <p>So I tried doing this using <code>AFHTTPRequestOperationManager</code>, which appears to be the replacement for <code>AFHTTPClient</code> in AFNetworking 2.0 as shown below:</p>
  
  <p>AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];</p>
  
  <pre><code>[operationManager POST:@"https://api.imgur.com/3/image/1Nf1quS" parameters:@{@"Authorization": @"Client-ID ---"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSLog(@"success");
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"failure");
  }];
  </code></pre>
  
  <p>Basically tried to send a request with authorization information (I removed my ID for this post). It keeps giving "failure" as a response however.</p>
  
  <p>So I tried playing around with the <code>credential</code> property but <code>NSURLCredential</code> seems to be based off a username and password, and I have neither of those as I just need my client ID.</p>
  
  <p>So I tried a completely different way again:</p>
  
  <pre><code>AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
  NSMutableURLRequest *request= [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.imgur.com/3/image/1Nf1quS"]];
  [request addValue:@"Client-ID ---" forHTTPHeaderField:@"Authorization"];
  
  [operationManager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSLog(@"success");
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"fail");
  }];
  </code></pre>
  
  <p>This time using the authorization things as a value on the request. But this one actually never even logged anything.</p>
  
  <p>I'm quite new to API use, so I'm really confused what I'm doing wrong.</p>