Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2010, 08:39 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 19
dragi is on a distinguished road
Default How to add an UserAgent to a JSON Request?

Hello,

I want to use the search.twitter.com API. As far as I understood I have to create an URL String that contains my Search Parameters like "http://search.twitter.com/search.json?q=test&rpp=5" and do this with the JSON Framework.
Twitter says in it's Docu that every Application should provide a valid User Agent to get the maximum Rate Limit per Hour. How do I add an UserAgent to this string and what is my UserAgent? The whole Web seems to assume that everyone knows what an UserAgent is and how to put it into your App but clearly I don't know and found nothing on how to add a UserAgent to a search.twitter.com string.

Can Someone give me a hint?

Thank you

dragi
dragi is offline   Reply With Quote
Old 09-02-2010, 08:50 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Depends how you're connecting to the URL, by default the useragent is set for you to something including the name of your app.
harrytheshark is offline   Reply With Quote
Old 09-02-2010, 09:13 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 19
dragi is on a distinguished road
Default

Thank you for you answer and because of that I've realized that it is nothing to put into the URL String.

Looks like this will work:

Code:
NSString* userAgent = @"My Cool User Agent";
NSURL* url = [NSURL URLWithString:@"http://whatsmyuseragent.com/"];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]
                                autorelease];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];

NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];
dragi is offline   Reply With Quote
Old 09-02-2010, 09:14 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Yuuup, that'll do it
harrytheshark is offline   Reply With Quote
Reply

Bookmarks

Tags
json, twitter

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 350
7 members and 343 guests
dre, freewind, hain, HemiMG, lendo, mottdog, oceanlablight
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:03 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0