Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Gregg Mojica
11,506 PointsCurl Command -H Square API
I'm developing an iOS app using the Square Connect API. I need to connect with the following command:
curl -H "Authorization: Bearer ACCESS_KEY"
https://connect.squareup.com/v1/me/payments
What's the iOS equivalent of this? Amit Bijlani Stone Preston
2 Answers
Gregg Mojica
11,506 PointsFinally figured it out!
NSString *pswd = @"XXXXXXXXX";
NSURL *url = [NSURL URLWithString:@"https://connect.squareup.com/v1/me/payments"];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
NSString *authValue = [NSString stringWithFormat:@"Bearer %@", pswd];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
Ryan Duchene
Courses Plus Student 46,022 PointsI don't think iOS/ObjC has an implementation of curl in the most technical sense, but I'm pretty confident that the NSURLConnection and NSMutableURLRequest classes should get you where you want to go.
I haven't taken very much iOS here, so I'm not sure if that will solve your problem. If you run into issues, post back here, and I'll try to help you further. :)
Gregg Mojica
11,506 PointsI've used both classes attempting to connect to the API and each time it returns validation failed or something to that avail. Can you post a code example? Thanks!!
Ryan Duchene
Courses Plus Student 46,022 PointsWill this Stack Overflow post help?
Gregg Mojica
11,506 Pointshmmm...still didn't work. Can you provide a code example? I used the code from that SO post but it didn't work. Maybe I'm doing something totally stupid.
Ryan Duchene
Courses Plus Student 46,022 PointsI wish I could help more, but I don't know much about it either. :( I'm sorry about that. Other than doing the obvious Google search, I'm not sure how to solve your problem.
Gregg Mojica
11,506 PointsOK, thanks for your help. I'll keep searching...
Ryan Duchene
Courses Plus Student 46,022 PointsWait a second...I think I found something.
Gregg Mojica
11,506 PointsThanks for your help, I finally figured it out!