Error Sending Dm On Twitter Unauthorized
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn
Twitter Internal Server Error When Tweeting
more about Stack Overflow the company Business Learn more about hiring developers or posting internal server error twitter photo upload ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Direct Message Instagram
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Send Direct Messages using twitter API up vote 0 down twitter direct message vote favorite I trying to use twitter API to send direct messages using C# but Twitter keeps saying: "The remote server returned an error: (401) Unauthorized." But this has no sense because I could use other API calls where I was authorized. Some background info: I created an application with these access permissions: Read, Write and Access direct messages I could succesfully post a status in my timeline: https://dev.twitter.com/docs/api/1/post/statuses/update your message could not be sent twitter I could also retrieve all the direct messages sent to me: https://dev.twitter.com/docs/api/1/get/direct_messages The problem is when I try to send a direct message: https://dev.twitter.com/docs/api/1/post/direct_messages/new c# twitter twitter-oauth share|improve this question edited Jan 12 '12 at 20:16 GEOCHET 16.4k156085 asked Jan 12 '12 at 20:13 Pato Loco 419518 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted I couldn't figure out yet what's wrong, but I could make it work using a open source project called tweetsharp. You can download it and see the code that works: Tweet Sharp here is a code example var service = new TwitterService(consumerKey, consumerSecret, accessToken, accessTokenSecret); var user = service.VerifyCredentials(); var result = service.SendDirectMessage(recipient, message); share|improve this answer answered Jan 13 '12 at 20:30 Pato Loco 419518 I'm (desperately I might add ;) looking for a codesampe how to get this to work. Your code sample looks good, but to get the accessToken value filled, the user has to enter a pin right? I have no idea how to set this up. Could you please share your full code as your answer? It would help me a lot! Thanks so much! –Flo Sep 29 '14 at 21:28 add a comme
string
Twitter Something Is Technically Wrong
ScreenName, string Msg) { // oauth application twitter help keys //Using API getting secret in token and token in secret var
Twitter Status
oauth_token = Convert.ToString(ViewState["Accesstoken"]); //"622979601-fB61G2YL49PQPKnN8u0sirUwscggUUS5x7Ly7urG"; var oauth_token_secret = Convert.ToString(ViewState["AccesstokenSecret"]); //"ZYlYneKW1FQt7cNuJc7PgRhjfG2yp7Og1AgvQC70kuHam"; var oauth_consumer_key = ConsumerKey; var oauth_consumer_secret = ConsumerSecret; // http://stackoverflow.com/questions/8841638/send-direct-messages-using-twitter-api oauth implementation details var oauth_version = "1.0"; var oauth_signature_method = "HMAC-SHA1"; // unique request details var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())); var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var oauth_timestamp = https://twittercommunity.com/t/send-direct-message-from-c-web-application-getting-unauthorized-401-error/45572 Convert.ToInt64(timeSpan.TotalSeconds).ToString(); // create oauth signature var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + //"&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&status={6}&screen_name={7}";//&result_type=mixed&count=4 "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}"; var baseString = string.Format(baseFormat, oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, oauth_token, oauth_version //Uri.EscapeDataString(Msg), //,Uri.EscapeDataString(ScreenName) ); baseString = string.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString)); var compositeKey = string.Concat(Uri.EscapeDataString(oauth_consumer_secret), "&", Uri.EscapeDataString(oauth_token_secret)); string oauth_signature; using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey))) { oauth_signature = Convert.ToBase64String( hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString))); } // create the request header var headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " + "oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " + "oauth_token=\"{4}\", oauth_signature=\"{5}\", " + "oauth_version=\"{6}\""; var authHeader = string.Format(headerFormat, Uri.EscapeDataString(oauth_nonce), Uri.EscapeDataString(oauth_signature_method), Uri.EscapeDataString(oauth_timestamp), Uri.EscapeDataString(oauth_consumer_key), Uri.EscapeDataString(oauth_token), Uri.EscapeDataString(oauth_signature), Uri.EscapeDataString(oauth_version) ); ServicePointManager.Expect100Continue = false; // make the request //var postBody = "?text" + Uri.EscapeDataString(Msg);// +"&result_type=mixed&count=4";// +"&count=100";// var postBody = "?text" + Uri.EscapeDataString(Msg) + "&screen_name=" + Uri.Escap
Việt Log in Sign up How can we help? Help Center Using Twitter My account Fix a problem Policies and reporting Breadcrumb Navigation Help Center Using Twitter The basics Using Twitter https://support.twitter.com/articles/14606 Using Twitter The basicsSigning upSigning up with TwitterThe Twitter glossaryNew user FAQsGetting started with TwitterTweetingPosting replies and mentionsSharing and watching videos https://wiki.bitlbee.org/HowtoTwitter on TwitterTwitter PollsRetweeting another TweetPosting photos or GIFs on TwitterPosting links in a TweetDeleting a TweetAdding your location to a internal server TweetUsing hashtags on TwitterLiking a TweetPosting a TweetSharing a TweetDiscovering TweetsTweet translationFind friends by uploading your contactsFinding people on TwitterAbout the Connect tabReceiving recommendations from TwitterAbout MomentsCustomizing your experienceApproving or denying follower requestsAbout public and protected TweetsProtecting and unprotecting your TweetsUnfollowing people internal server error on TwitterMuting accounts on TwitterBlocking accounts on TwitterAdvanced options for using blockLearn how to control your Twitter experienceDirect MessagesAbout Direct MessagesDirect Message FAQsSearchFAQs about top search resultsUsing advanced searchUsing Twitter searchSaving searches Back Beyond the basicsDo more with TwitterUsing advanced searchMaking images accessible for people on TwitterManaging multiple Twitter accountsUsing Twitter listsAbout the Twitter Translation CenterGetting started with the Translation CenterAbout Twitter DashboardUsing Twitter AlertsIncreasing your reach, one Tweet at a timeAbout the Twitter Engage appUsing Twitter with FacebookAbout @TwitterNotifyIn-Tweet purchases on TwitterDonations on TwitterCreating a MomentTwitter on sites and blogsAdding the Tweet button to your websiteAdding a Follow button to your websiteAdding Twitter Buttons to your websiteHow to embed a timelineEmbedding a Tweet on your website or blogMore about TwitterFAQs about followingProviding fe
Map ------------------------ Rename Page Delete Page ------------------------ Subscribe User ------------------------ Remove Spam Revert to this revision Package Pages Sync Pages ------------------------ Load Save SlideShow Setting up a Twitter account in BitlBee BitlBee has native support for Twitter via the Twitter API. You need to use BitlBee 3.2.1 (or newer) due to server side api changes. None of the previously mentioned workarounds are effective anymore. If you're stuck with 3.0 or 3.2 in a debian based distro, there's a repository at http://code.bitlbee.org/debian/. Connecting To use your Twitter account in BitlBee: 1 11:45:03