I'm interested in integrating the Imgur API into my app, and it states that in order to get image information (basically the extent of what I need right now) I just need to register my app, no need to log in with user information or anything.
Great, I'm using AFOAuth2Client (specifically this pull request so it works with AFNetworking 2.0). I have my client key and client secret, but I can't seem to figure out how to get to an image.
I try the following code (personal API details removed):
AFOAuth2Client *oauthClient = [AFOAuth2Client clientWithBaseURL:[NSURL URLWithString:@"https://api.imgur.com/"] clientID:@"---" secret:@"---"];
[oauthClient authenticateUsingOAuthWithURLString:@"https://api.imgur.com/oauth2/authorize" parameters:nil success:^(AFOAuthCredential *credential) {
NSLog(@"Yes");
} failure:^(NSError *error) {
NSLog(@"No");
}];
But I always get No
outputted. How do I properly authenticate so I can then make calls to the API to get information about an image? (As detailed here.)
As I've been told I don't need OAuth period, I tried the following with AFNetworking 2.0 (to no avail):
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager POST:@"https://api.imgur.com/3/image/1Nf1quS" parameters:@{@"Authorization": @"Client-ID myactualclientidisremoved"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failure");
}];
First, the example is using Imgur API v2 which is old and unsupported. You should be using API v3.
Also note that:
For public read-only and anonymous resources, such as getting image info, looking up user comments, etc. all you need to do is send an authorization header with your client_id in your requests.
from docs at https://api.imgur.com/oauth2 -- so you don't really need OAuth for what you're doing.
There is some example Imgur API code that might help you, listed at https://api.imgur.com/ -- the Android example might be more relevant to you, since it uses Java, but unsurprisingly it comes with all the overhead of an Android project, compared with a plain Java application.