Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 887847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:17:50+00:00 2026-05-15T13:17:50+00:00

My site uses a php function to tweet an update whenever an event occurs.

  • 0

My site uses a php function to tweet an update whenever an event occurs. Right now I’m using the classic login technique, so the username and password for the associated Twitter account are just hard-coded in. The function looks like this:

function sendTweet($msg)
{
    $username = 'username';
    $password = 'password';
    $url = 'http://twitter.com/statuses/update.xml';
    $curl_handle = curl_init();

    curl_setopt($curl_handle, CURLOPT_URL, "$url");
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$msg");
    curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");

    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);
}

I’d like to rewrite it to use OAuth, mostly to avoid problems down the road when classic login is deprecated, but also so that it will use the name of my application instead of “from API” after every tweet.

All the examples I can find involve creating an authentication system, which sends the user to twitter.com to approve the authentication request, then sends them back to the originating site with an appropriate token. For my application though there’s only one twitter account and it doesn’t belong to the user who initiates the action (who may not even know or care that he is initiating a tweet).

So how do I do this? The best option I can think of is to build a one-time-use script which will let me request an access token, then hard code that token into the sendTweet function. That seems like a lot of overkill for such a simple application, and it creates a potential problem down the road if Twitter ever expires the access token. The docs say they probably never will, but that applications should be designed to handle it gracefully if they do.

Does anyone have experience with a project like this? Is there a simpler and more graceful way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:17:51+00:00Added an answer on May 15, 2026 at 1:17 pm

    Using abraham PHP Twitter OAuth Library and use single access token.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.