Comments (7)
Do you want to replace the whole network stack from RestKit or just add some bits from STHTTPRequest?
Do you only need to build some headers? which ones exactly? the basic auth. header? or some OAuth specific authentication headers?
STHTTPRequest does not handle the OAuth protocol. It's just a wrapper around NSURLConnection. The OAuth stuff is implemented in STTwitterOAuth.m. Note that it is Twitter specific and may not work for other OAuth implementations.
from sttwitter.
Well, the way I've been using RestKit to handle network operations is to pass it a URL in the form of requestURL
:
RKManagedObjectRequestOperation *requestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:requestURL] responseDescriptors:@[jsonResponseDescriptor]];
What I've done thus far with STTwitter is to create an instance of an app-only auth like so:
STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:kTwitterConsumerKey consumerSecret:kTwitterConsumerSecret];
and then execute
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken)
It's in the success block that I'd like to integrate it into RestKit with the method at the top. I'm still somewhat new to Oauth, but from what I've read it seems at this point an Oauth signature is passed to Twitter with the appropriate REST command (GET in this case) and credentials.
I placed a breakpoint on getResource:
in STTwitterAppOnly.m and stepped into it all the way through execution, but couldn't seem to see where or how exactly it was making the GET request to Twitter's API. I see where it's setting the request headers with the authorization, using the appropriate API URL, and setting the REST request type, but how does it then send the entire signature to Twitter when it authenticates API requests with the bearer token? Is it done in the form of a HTTP request or as a curl command? I'm looking at step 3 on this page: https://dev.twitter.com/docs/auth/application-only-auth.
And I'm seeing how the signature is constructed on this page: https://dev.twitter.com/docs/auth/creating-signature.
Sorry, I'm a bit new to this, but would like to learn and help out wherever possible!
Also, don't know if it will help, but in this post about halfway down the lead on RestKit talks about some ideas on how to implement Oauth into it: RestKit/RestKit#696.
Thanks,
Evan
from sttwitter.
Hey- just wanted to see if you had any ideas on this? Thanks!
from sttwitter.
Sorry for the delay, I have been very busy these last few weeks.
"App only" requests are quite simple, they just have an 'Authorization' header and do not need the full set of OAuth headers. There is no signature in "app only" requests, so the page https://dev.twitter.com/docs/auth/creating-signature is not relevant for these requests.
So, in these "app only" requests, the header is set with [r setHeaderWithName:@"Authorization" value:@"xxx"]
in -[STTwitterAppOnly postResource:baseURLString:parameters:useBasicAuth:successBlock:errorBlock:]
.
I tried to summarize the three kinds of authentication (PIN-based Authentication, xAuth Authentication and Application Only Authentication) in section 2 of this article: http://seriot.ch/abusing_twitter_api.php#2 maybe it can help you in getting a clearer view.
Please keep on asking questions if needed, I'll try to help if I can.
from sttwitter.
No worries, I completely understand. Thanks so much for the explanation, I appreciate it. I decided to go a slightly different route, as we will probably need to do user auth soon—I'm using STTwitter for all the auth parts and am just passing the returned JSON array to RestKit to do all the mapping/Core Data stuff.
The only question I have is regarding the JSON array that's returned with various REST methods—it seems that, in order to perform Core Data operations on it, I'll have to iterate through each index of the array, which seems somewhat intensive and clunky from RestKit's end (as I could have an array with 150-200 objects in it). Is it possible to directly access the returned JSON and not as an array, so RestKit could just parse it as one blob? Initially, it's returned as id json
in STTwitterAppOnly.m:
- (void)getResource:(NSString *)resource
parameters:(NSDictionary *)params
successBlock:(void(^)(id json))successBlock
errorBlock:(void(^)(NSError *error))errorBlock
and then you serialize it into an array.
Thanks!
Evan
from sttwitter.
One of the goals of STTwitter is to convert Twitter API responses into Cocoa objects that can be used directly by a Twitter client. The lower classes STTwitterOAuth / STTwitterOAuthOSX / STTwitterAppOnly handle the protocol and deserialize the JSON response into NSArray / NSDictionary. STTwitterAPIWrapper sits on top of these classes. It knows Twitter API endpoints and knows how to extract specific data from their responses.
If you need to access the full JSON response from Twitter as NSArray / NSDictionary, you can access it by bypassing the STTwitterAPIWrapper layer and use the lower classes directly. Or you could implement -[STTwitterAPIWrapper getResource:parameters:successBlock:errorBlock:]
so that it calls the same method on _oauth
.
If you need to access the JSON response as a string, that is "uninterpreted" JSON, you could add something like this to STTwitterOAuthProtocol
:
- (void)getResource:(NSString *)resource
parameters:(NSDictionary *)params
rawSuccessBlock:(void(^)(NSData *responseData))rawSuccessBlock // or NSString if you wish
errorBlock:(void(^)(NSError *error))errorBlock
Let me know if it helps or if we can improve STTwitter in any way.
from sttwitter.
Ok, thanks!
from sttwitter.
Related Issues (20)
- _getUserStreamStallWarning:... cancelling on receiving friends list?
- Attachment_url HOT 2
- postTokenRequest never callsback success or failure HOT 1
- Use of API only available in iOS 8
- Support for new events APIs HOT 1
- Modify character counter to take into account usernames at beginning of tweets HOT 1
- Carthage Support HOT 1
- STTwitter and iOS 11 HOT 2
- Twitter API request with JSON body HOT 2
- STTwitter in macOS 10.13 HOT 3
- Saving account to device settings HOT 1
- Perform video uploads from local NSData
- SLServiceTypeTwitter is deprecated in ios11 objc "SLServiceTypeTwitter' is deprecated: first deprecated in iOS 11.0"
- media_ids parameter is invalid.
- newest XCode throws warnings: This block declaration is not a prototype
- ⚠️ Legacy APIs must be migrated to new ones within 5 months! HOT 2
- Supporting “full_text” of a tweet with “tweet_mode=extended” HOT 1
- Twitter API 2.0
- How do I set up to jump to the Twitter App to sign in?
- Thread 1: "-[STTwitterAppOnly postTokenRequest:authenticateInsteadOfAuthorize:forceLogin:screenName:oauthCallback:errorBlock:]: unrecognized selector sent to instance 0x280371140" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sttwitter.