How to send direct message with Twitter? - iphone

in my iphone application i have to send direct message throughout twitter,
the problem is that twitter had changed the authentication from basic authentication to oauth
and tutorial on the Web are out of date
so i use SAOauthTwitterEngine for the authentication part and all ok. but these classes don't use the api, so i have to use MGTwitterEngine for this.
the problem is that MGTE dont have oauth but only xauth and basic authentication, and i cant use this together anyone know how to do it? or know a tutorial that explain it.
thanks a lot.

i suggest you OAuth because xAuth requires you to send an email to twitter askeing them to give you the permission, and you have to write a reort on your application (this isn't good for a testing app)
have you tried this?
https://github.com/bengottlieb/Twitter-OAuth-iPhone

in my app I am sending direct messages to my twitter followers by using MGTwitterEngine let have a look:
appDelegate._engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
appDelegate._engine.consumerKey = kOAuthConsumerKey;
appDelegate._engine.consumerSecret = kOAuthConsumerSecret;
once you get authenticated this method get called
#pragma mark SA_OAuthTwitterControllerDelegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *)username {
NSLog(#"Authenicated for %#", username);
[appDelegate._engine sendDirectMessage:#"Test for Twitter direct message" to:username];
}
Hope this will help you.

Related

Verify Twitter login from iPhone on the server side

Ok, so I've currently implemented Facebook login in my app the following way:
I use the official FB framework to login the user. When I login, I get a authentication token, which is sent to my server. I then do another verification of the user (e.g. get "me" from Facebook, using the auth-token), and then return 32 char random key, which is used to identify the user in subsequent API-calls (to my server). An example.
I'm trying to figure out how to do the same with twitter, but I can't understand how to get the oath token in iOS? I have the server-side part working in another app, but no token to verify...
Please advice – is this (the FB way) how I should be doing this, or how would you go about the verification process?
Sean Cook, engineer # Twitter has a github repo with a simple app that do exactly what you are trying to do, I'using this code in my app and it works like a charm.
There's a good article at dev.twitter.com describing exactly that. Basically you'll have to first get a special request token by setting the x_auth_mode parameter to the value reverse_aut and then get the proper access token by sending what you got in the first step as x_reverse_auth_parameters.
If you are going for an iOS 5 solution, you can import this into your header file
#import < Twitter/TWTweetComposeViewController.h >
and then in the .m file where you want to authenticate
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController* twc = [[TWTweetComposeViewController alloc] init];
[twc addImage:uiImage
[self presentModalViewController:twc animated:YES];
twc.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
if (result == TWTweetComposeViewControllerResultCancelled)
NSLog(#"Tweet compostion was canceled.");
else if (result == TWTweetComposeViewControllerResultDone)
NSLog(#"Tweet composition completed.");
// Dismiss it
[self dismissModalViewControllerAnimated:YES];
};
[twc release];
} else
{
//can't tweet
}
You can also add URLs, text and other sorts of information.
Edit: You can find a tutorial on adding the needed Library to your project here,
https://dev.twitter.com/docs/ios/how-add-twitter-framework-your-ios-project

iphone - How to get friends/ids with Twitter API?

How can I get Friends/Friend's IDs of my twitter account using Twitter API?
In this tutorial https://github.com/bengottlieb/Twitter-OAuth-iPhone and example of, I can just send the updates or send any direct messages, but I can't get any direct messages or Friend's IDs or any other things that can be found from the get methods.
How can I find any data that was parsed from the get methods? (Example: getPublicTimeline, getUpdate:(unsigned long)updateID, getDirectMessagesSinceID:, etc..)
Can anyone suggest how to solve this problem?
https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=screennameofUser
yes.You have getFriends method.Also You have getFollowersIncludingCurrentStatus method.These methods will return to the following Callback,
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
{
//Here You can parse userInfo and get the list
}

Using retweeted_by API with MGTwitterEngine - keeps on returning error 404

I'm trying to add a method to MGTwitterEngine to use twitter's retweeted_by API ( http://dev.twitter.com/doc/get/statuses/:id/retweeted_by ).
Here is what I've added to MGTwitterEngine.m (all the OAuth stuff is done, the other methods inside the engine work fine)
-(NSString *)getUsersWhoRetweetedTweetWithID:(unsigned long)ID {
NSString *path = [NSString stringWithFormat:#"statuses/70482402362933249/retweeted_by.xml"];
return [self _sendRequestWithMethod:nil path:path queryParameters:nil body:nil
requestType:MGTwitterUsers
responseType:MGTwitterUsers];
}
Note: I've already included the .xml format and a status ID - just to ensure there's nothing wrong with the data I'm passing on. When I call [_engine getUsersWhoRetweetedTweetWithID:0]; from my app controller, error 404 is returned "The operation couldn't be completed. (HTTP error 404.)".
I've tried it with a parameters NSDictionary & tried changing the request & response types.
Currently, I don't make use of MGTwitterEngine to check who RTd a tweet, I just use a non OAuth'd method - however this will not return protected users who RTd a tweet.
Can anyone give me a point in the right direction - it's being driving me crazy for the past few days! I really appreciate any input :)
Take a look here.....
How to do a RETWEET on an iPhone twitter app (MGTwitterEngine)
MGTwitterEngine does not support re-tweet method yet .. you have to manually add the parse to MGTwitterEngine .h and .m then the call out would be [_engine sendRetweet:(unsigned Long)];
Now I am in the process of trying to determine how you call out the unsigned long...if any one else has an answer to that I would be happy to hear it myself.

How to authorize user through a DIALOG with the NEW Facebook Connect iOS API?

I understand - http://developers.facebook.com/docs/guides/mobile/#ios -, seems really useful, but my app won't support multitasking, so this "cross safari" method won't work for me.
Is there a brief example somewhere (or can someone please copy here) an authentication process trough FBDialogs (with this so called "new" API)? I'm just getting know this SDK, so please as basic as you can.
Struggled to figure this out for a couple of hours...
Here is the solution to bypass fb app|background-safari authentication, and it is just to change in Facebook.m:
[self authorizeWithFBAppAuth:YES safariAuth:YES]
to
[self authorizeWithFBAppAuth:NO safariAuth:NO]
in the method:
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate
.
Verified it with the sample code without changing anything else (of course set kAppId to yours)
I was quite mad why on earth FB doesn't document this...
Hope it helps,
Cheers
All the magic is in
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate
which call [self authorizeWithFBAppAuth:YES safariAuth:YES] :
FBAppAuth:YES will try to authenticate using Facebook app if installed
safariAuth:YES will try to authenticate using Safari if device supports multitasking
So what you want is [self authorizeWithFBAppAuth:NO safariAuth:NO]
If you want to leave unmodified the Facebook SDK you can simply "expose" their private api :
#interface Facebook (Private)
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth;
#end
And then extend if with a category:
#interface Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate;
#end
#implementation Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate {
_permissions = [[NSArray arrayWithObjects:#"email", *(whatever you need)*, nil] retain];
_sessionDelegate = delegate;
[self authorizeWithFBAppAuth:NO safariAuth:NO]; // force in app auth
}
#end
Then use it almost normally :
Facebook *facebook = [[Facebook alloc] initWithAppId:MY_APP_FB_ID];
[facebook myAuthorize:self];
That's a popular request they didn't implemented, there are even pull requests with solutions...

MGTwitterEngine getting feeds - iPhone

So, in my app, I am trying to use MGTwitterEngine to read from a certain user on Twitter, and then log the recent posts in an array. Is it possible to do this with this library? I am trying to do this without logging in. Any help would be appreciate, thank you!
It can be easily done with MGTwitterEngine. You do it this way:
MGTwitterEngine *twitterng = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterng getUserTimelineFor:#"userName" sinceID:0 startingAtPage:0 count:8];
and it will call delegate method
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
Hope this helps.
You need to get the feed url that contains the rss feeds. You don't need to login for that. Use MGTwitterEngine to get the tweets and set them into array. Then you simply need to reload the tableview.
Hope this helps.
Thanks,
Madhup