Question

I'm getting a little confused on this seemingly simple concept. Basically I'm building a web app that will notify users via a Twitter Direct Message if an event occurred on their account with me. I'm building it in PHP with CakePHP as the underlying framework. I'd like to be able to send the direct message "from" the application via oAuth. I used the Twurl Console (at http://dev.twitter.com/console) to send a POST request via

http://api.twitter.com/1/direct_messages/new.xml?screen_name=<my screenname>&text=<content of dm>

When I check my DM's I basically get a DM from myself. Is that because the Twurl console uses your screenname when sending stuff from applications or because when calling the direct_message/new.xml you are sending a DM from your account which was authenticated with the test application in Twurl. In the end I'm looking to accomplish the same thing that spontwts does - notify you via DM when something happens on your account. Any input, resources, links, or code samples are very much appreciated :)

Was it helpful?

Solution

You can send the direct message via screen name of your followers by Where userID is the screen name of the person,

ConfigurationBuilder cb=new ConfigurationBuilder();

cb.setOAuthAccessToken("Your App Access Token");

cb.setOAuthAccessTokenSecret("Your App Token Secret");

cb.setOAuthConsumerKey("Your App ConsumerKey");

cb.setOAuthConsumerSecret("Your App ConsumerSecret");

cb.setIncludeRTsEnabled(true);


TwitterFactory tf=new TwitterFactory(cb.build());


Twitter twitter=tf.getInstance();

twitter.sendDirectMessage(userID, "Message");

And Provide the Read/Write/Direct Message Permission in the app.

OTHER TIPS

First of all, if you want your application to interface with Twitter, you have to register it first. The Twitter Document explains exactly how this is done.

Once you have this, follow the OAuth version 1 Authorization protocol in getting an Access Token. By having an access token, you can essentially call Twitter protected resources. The full protocol (given on link above) shows you how to achieve this. The console can easily bypass the OAuth protocol since you've authenticated through Twitter (which OAuth calls, the service provider). OAuth allows only the service provider to do client credential authentication.

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top