iOS Tumblr Integration using oauth - ios

Trying to understand how this all works. New to oauth and api integrations.
Not looking for a better way. Looking to understand and expand on what this is doing.
I followed this tutorial and have it working
through part 3.
I kind of understand, but having a hard time connecting the code to the Tumblr API documentation.
The tutorial leaves off with having the user's Access Token.
How do I use the Access Token to get the users info with api.tumblr.com/v2/user/info in xcode?
With this information I might be able to put together an understanding in my head.
Code example would be much appreciated!

#Ir100,
use the same acess_token and secret_key you generated via OAuth Library and just change your request url(API) because every time you have to send other parameter for API call.
_consumer = [[OAConsumer alloc] initWithKey: _consumerKey secret: _secretKey];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL: url consumer: _consumer token:token realm:nil signatureProvider: nil] ;
if (!request) return;
if (self.pin.length)
token.verifier = _pin;
[request setHTTPMethod: #"POST"];
if (_api)
[request setHTTPMethod: #"GET"];
NSMutableArray *params = [[NSMutableArray alloc] initWithArray:request.oa_parameters];
request.oa_parameters = params;
OADataFetcher *fetcher = [[OADataFetcher alloc] init] ;
[fetcher fetchDataWithRequest: request delegate: self didFinishSelector: success didFailSelector: fail];

Related

Unable to add a header to NSMutableRequest

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]] autorelease];
[request setValue:encryptedValue forHTTPHeaderField:#"EncString"];
I could spot all other headers in the request but this specific header is missing, can any one let me know what could be the reasons.
I have tried the following code:
NSString *tempURL = #"https://stackoverflow.com/questions/50701101/unable-to-add-a-header-to-nsmutablerequest";
NSString *encryptedValue = #"whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]];
[request setValue:encryptedValue forHTTPHeaderField:#"EncString"];
NSLog(#"%#", request.allHTTPHeaderFields);
The output is:
{
EncString = "whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
}
which looks good. There is no reason to suspect the code you provided is responsible for the issue. Maybe you should check one of the following:
Is encryptedValue truly a valid object to be placed into header (is string, not too long, no very special characters)
Is the object you are printing really this specific request (printing NSLog(#"%p", request); returns same result)
In no place in this object a herder is being removed (if nothing else subclass NSMutableURLRequest and override relevant methods to track what is going on)
If none of these work create a post with additional details on what you have done, where are you checking these headers and "could spot all other headers".

Rest call with amazon ios sdk to amazon elastic transcoder

I looked at the docs and i don't see support for elastic transcoding sdk for ios.
My use case is to move the file "videoFile.mp4" from "bucket1" in mp4 format to transcode and create the file "videoFile.webm" again back to "bucket1".
How can i use amazon sdk(code sample) to make the rest calls to do this task?
UPDATE:
I am able to get something going but i am having another issue.
But i am getting this message when I am making the call to https://elastictranscoder.us-west-2.amazonaws.com/2014-06-16/jobs
<InvalidSignatureException>
<Message>Credential should be scoped to correct service: 'elastictranscoder'. </Message>
</InvalidSignatureException>
The code below is what i have tried.
AmazonCredentials *credentials = [[AmazonCredentials alloc] init];
credentials.secretKey = SECRET_KEY;
credentials.accessKey = ACCESS_KEY_ID;
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// dateString1, #"x-amz-date",
#"elastictranscoder.us-west-2.amazonaws.com:443",#"host",
#"application/x-amz-json-1.0", #"content-type",
length, #"content-length",
nil];
AmazonServiceRequest *request = [[AmazonServiceRequest alloc] init];
request.urlRequest.HTTPMethod = #"POST";
request.regionName = #"us-west-2";
request.serviceName = #"ets";
NSLog(#"***********************************************************************************************");
NSLog(#"***********************************************************************************************");
[AmazonAuthUtils signRequestV4:request headers:parameter payload:jsonStringData credentials:credentials];
NSLog(#"***********************************************************************************************");
NSLog(#"***********************************************************************************************");
NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:#"https://elastictranscoder.us-west-2.amazonaws.com"]];
[mutableRequest setHTTPMethod:#"POST"];
for(id key in parameter){
[mutableRequest setValue:[parameter objectForKey:key] forHTTPHeaderField:key];
}
NSLog([request.urlRequest valueForHTTPHeaderField:#"x-amz-date"]);
NSLog([request.urlRequest valueForHTTPHeaderField:#"Authorization"]);
// add the Authorization signature and the date
[mutableRequest setValue:[request.urlRequest valueForHTTPHeaderField:#"x-amz-date"] forHTTPHeaderField:#"x-amz-date"];
[mutableRequest setValue:[request.urlRequest valueForHTTPHeaderField:#"Authorization"] forHTTPHeaderField:#"Authorization"];
[mutableRequest setHTTPBody:[jsonStringData dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:mutableRequest delegate:self];
In general, you should set up a pipeline from the AWS Management Console because it is a one-time setup. It does not make sense to create a pipeline from mobile devices. From mobile devices, you should just upload video files to your Amazon S3 bucket. A backend server (e.g. Amazon EC2 and AWS Elastic Beanstalk are both good options) should monitor the bucket and create jobs for Elastic Transcoder. AWS just announced AWS Lambda, and you may want to check it. Once the job is done, you can use Amazon SNS to get notified.

How do I set up and implement HTTP method for authorization?

I'm trying to get into a webAPI my classmate created with my iphone APP I've created. Right now, it connects, but my app just crashes because it tells me that I need authorization. So if for example, the username is abc and password abc123, How would I implement the HTTP method specifically to get passed authorization??
NSString *geturl = #"http://192.168.1.96:50364/api/transaction" ;
setValue:(NSString*)" " forHTTPHeaderField:(NSString*)username;
getjson *mds=[[getjson alloc] init];
SEL selector = #selector(addData:);
[mds setDirectionsQuery:geturl
withSelector:selector
withDelegate:self];
Edit: if the above problem is too confusing, what is the basic syntax/code for setting up the value and the key for username and password? I am sure
setValue:(NSString*)"abc " forHTTPHeaderField:(NSString*)username;
setValue:(NSString*)"abc123 " forHTTPHeaderField:(NSString*)password;
is not correct. compiler is not letting me run the program.
Your strings are missing #
Try setValue:(NSString*)#"abc " forHTTPHeaderField:(NSString*)username; although if the code you pasted is complete, it doesn't say what your setting values to.
I personally use NSMutableRequest and create the request and authorisation like this. Note that the auth gets Base64 encoded:
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:_urlString]];
NSString *basicAuthCredentials = [NSString stringWithFormat:#"%#:%#", username, password;
NSString *authValue = [NSString stringWithFormat:#"Basic %#", AFBase64EncodedStringFromString(basicAuthCredentials)];
[urlRequest setValue:authValue forHTTPHeaderField:#"Authorization"];

How to get friends profile picture from gmail contacts?

I'm trying to import GMail contacts (friends list). I have got friends' mail id, name, and phone number, but if I tried to get the images it says "401 error".
The code I have used is as follows:
GDataLink *photoLink = [contact photoLink];
NSLog(#"%#",photoLink);
NSURL *imageURL = [photoLink URL];
NSLog(#"image url = %#",imageURL);
How can I get friends' profile picture? Where did I go wrong?
Looking at some other (public) code that's roughly the same as what you're doing, I see that you should be using an auth token with these photo links. Without that auth token, Google assumes you might be malicious and will send back a 401 error.
E.G.
GDataLink *photoLink = [contact photoLink];
NSString *imageETag = [photoLink ETag];
if (imageETag == nil || ![mContactImageETag isEqual:imageETag]) {
if (imageETag != nil) {
// get an NSURLRequest object with an auth token
NSURL *imageURL = [photoLink URL];
GDataServiceGoogleContact *service = [self contactService];
// requestForURL:ETag:httpMethod: sets the user agent header of the
// request and, when using ClientLogin, adds the authorization header
NSMutableURLRequest *request = [service requestForURL:imageURL
ETag:nil
httpMethod:nil];
[request setValue:#"image/*" forHTTPHeaderField:#"Accept"];
GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[fetcher setAuthorizer:[service authorizer]];
[fetcher beginFetchWithDelegate:self
didFinishSelector:#selector(imageFetcher:finishedWithData:error:)];
}
}
}

With the AWSiOS SDK how do you do a HEAD request on an S3 object?

I'm looking to use the SDK (can't use ASI) to do HEAD requests on objects before I download them to determine the size. Is there a provided way to do this I'm overlooking, or am I forced to build up my own S3Request, setting the httpMethod property to be "HEAD" and passing the constructed S3Request to the invoke: method of AmazonS3Client ?
Building the request myself gets a little dicey as I'm using federated users, so I wanted to make sure I wasn't duplicating something I had overlooked.
I am a maintainer of the AWS SDK for iOS. You can also use the S3GetObjectMetadataRequest to do the same thing.
S3GetObjectMetadataRequest *request =
[[S3GetObjectMetadataRequest alloc] initWithKey:FILE_NAME withBucket:BUCKET_NAME];
S3GetObjectMetadataResponse *response = [s3 getObjectMetadata:request];
int64_t fileSize = response.contentLength;
Turned out to be fairly straight forward, but still wondering if there's a more accepted way of doing a HEAD.
S3GetObjectRequest *headRequest = [[[S3GetObjectRequest alloc] initWithKey:keyname withBucket: [bucketname]] autorelease];
headRequest.httpMethod = #"HEAD";
S3Response *headResponse = [[S3Response alloc] init];
headResponse = [self.awsConnection invoke:headRequest];

Resources