views:

17

answers:

1

I am trying to post a status update to Twitter. I wrote an API call so that when I do

http://.....&token=$token&s=$token_secret&msg=hello ...it works fine when I type the URL into the browser. The status is posted correctly.

However, when I want to post the status via file_get_contents($url) where the $url is the same as how it worked from the browser, I receive a "failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized"

I did some tests, and it has nothing to do with url encoding. I am doing that properly.

So does anyone know why it works through the browser, but not through the code? Does Twitter block non-browser user agents?

Thanks a lot for any help.

A: 

Sounds like when you try it in the browser, you are logged in as yourself, so your post is going through. However, when you run it in your code, it doesn't send your cookies, so is not logged in, and therefore is not authorized to post.

Is your code attempting to log in at all?

zigdon
Thanks for the guess. We realized the problem was actually the Apache authorization security...When doing it through the browser we simply login with our credentials and since the browser saves our credentials we forgot we ever had to do it. Some simple CURL headers in the code to authorize with the apache server fixed the job.
ApexDodge