Jump to content

Recommended Posts

Posted

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

Posted

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. :)

Posted

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?

Posted (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 by jbach
Posted

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;

?>

Posted

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!

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...