jbach Posted January 18, 2010 Posted January 18, 2010 Hi having problems getting a proxy script to work. Getting the following error message "function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden..." Can someone help? this is the script //SCRIPT BEGINS <?php // PHP Proxy $url = 'http://'; if (isset($_GET['sd']) && $_GET['sd'] != '') { $url .= $_GET['sd'].'.'; } //ensure only twitter domains are used $url .= 'twitter.com/'; if (isset($_GET['path']) && $_GET['path'] != '') { $url .= $_GET['path']; } //you can change this to set mimeType via parameters, but //chances are you want xml $mimeType = 'application/xml'; $response = file_get_contents($url); if ($mimeType != "") { header("Content-Type: ".$mimeType); } echo $response; ?> //SCRIPT ENDS Quote
TCH-Thomas Posted January 18, 2010 Posted January 18, 2010 While I have no answer to why this isn´t working I wanted to let you know that there is no need to double post. We do read every single post. As for the problem, hold on and someone will probably know the answer. Quote
OJB Posted January 18, 2010 Posted January 18, 2010 A 403 means that the server you are requesting (in this instance twitter) is denying your request. They have possibly blocked your IP or User Agent. Doesn't Twitter offer an API for this sort of thing? What is it you are trying to do with the script exactly? Quote
jbach Posted January 18, 2010 Author Posted January 18, 2010 (edited) Yes, thought I posted in the wrong forum but didn't know how to delete my original post. In a nutshell I'm building a Twitter client in actionscript and using OAuth for authentication. The initial login (directing the user to twitter's OAuth sign in) works when I compile on the desktop, but NOT so far in a web browser (which requires the php proxy). A php proxy is required because 1- flash has strict security requirements and requires just a crossdomain.xml file to be defined on the remoter server 2-BUT Twitter doesn't allow this crossdomain.xml file The basic steps for OAuth authentication are 1-User first registers their application and obtains a key and secret 2-User requests a REQUEST token(on sign-log in) from Twitter 3-Twitter replies with the request token key 4-This request token is then appended to the Twitter OAuth sign in url at http://twitter.com/oauth/authorize?oauth_token=<insert request key here> 5-On successful sign in, Twitter marks the original request token as user-authorized. The whole process seems a bit convoluted, but OAuth has a number of advantages and is Twitter's recommended scheme for authorization moving forward. Where I seem to be stumbling is step 4, the request token key is not being appended to the OAuth sign in url. Edited January 18, 2010 by jbach Quote
OJB Posted January 18, 2010 Posted January 18, 2010 Unfortunately I am not a flash developer nor an OAuth expert so I can't really help out there I am afraid. Quote
jbach Posted January 19, 2010 Author Posted January 19, 2010 Unfortunately I am not a flash developer nor an OAuth expert so I can't really help out there I am afraid. ok But would you be able to tell me if the following should work? <?php $url = 'http://'; //ensure only twitter domains are used $url .= 'twitter.com/'; if (isset($_GET['path']) && $_GET['path'] != '') { $url .= $_GET['path']; } $mimeType = 'application/xml'; $response = file_get_contents($url); if ($mimeType != "") { header("Content-Type: ".$mimeType); } echo $response; ?> Quote
jbach Posted January 19, 2010 Author Posted January 19, 2010 or even simpler <?php $content = file_get_contents($_GET['url']); if ($content !== false) { echo($content); } else { // there was an error } ?> Do I need to worry about setting the content type header? Thanks in advance! Quote
jbach Posted January 19, 2010 Author Posted January 19, 2010 ok getting close...I may start a new post as Im really trying to get this to work this morning My php so far <?php $content = 'http://'; $content .= file_get_contents($_GET['path']); if ($content !== false) { echo($content); } else { // there was an error } ?> The browser error message I get: Warning: file_get_contents(twitter.com/oauth/authorize?oauth_token=) [function.file-get-contents]: failed to open stream: No such file or directory in /home/bitstre/public_html/twitter/proxy.php on line 3 http:// Any feedback welcome! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.