2011-04-22 82 views
2

我想出了這個twitter項目的閃光燈,一旦我完成了,並試圖把它在網上我遇到了沙箱錯誤。從我讀過的它看起來像我只需要設置一個PHP代理文件。我得到並理解。我所能找到的所有教程都是針對簡單的URL,沒有在URL中傳遞GET數據。對於我的項目來說,GET數據是動態的,所以我不能只在php代理中放置一個設置url,並且我不明白php是否足夠了解如何獲取代理網址中的數據。 所以這裏是我所知道的如何在Flex中編輯: enter image description hereFlash代理服務器的twitter嘰嘰喳喳(動態獲取陣列)

繼承人一個完整的例子API調用我需要做:

http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=brybam&?page=1 

,這裏是一個PHP代理腳本,在網上reccomended:

<?php 

$post_data = $HTTP_RAW_POST_DATA; 

$header[] = "Content-type: text/xml"; 
$header[] = "Content-length: ".strlen($post_data); 

$ch = curl_init($_GET['url']); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

if (strlen($post_data)>0){ 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
} 

$response = curl_exec($ch);  
$response_headers = curl_getinfo($ch);  

if (curl_errno($ch)) { 
    print curl_error($ch); 
} else { 
    curl_close($ch); 
    header('Content-type: ' . $response_headers['content-type']); 
    print $response; 
} 


?> 

好吧,getti ng開始我只需要將php腳本製作成一個類似twitter.php的文件,然後將其放在我的域中即可。然後,我假設在Flex中的HTTP服務設置網址框,並把它重新輸入的東西是這樣的:

http://mydomain.com/twitter.php?screen_name=brybam&?page=1 

SO什麼IM問的是,因爲我的PHP的理解是非常有限的,究竟我會採取上述腳本,並使其能夠通過

http://mydomain.com/twitter.php?screen_name=brybam&?page=1 

與Flex和能夠採取不同的潛在論點?

我想這可能是這樣的

$page = $_GET['page']; 
$screen_name = $_GET['screen_name']; 
在PHP文件

了,但是我不知道在哪裏我應該把變量爲使他們的URL的一部分

我敢肯定這是蛋糕,如果你知道PHP,這將是真棒,如果有人可以幫助我與此,謝謝!

編輯: 我想這一點,但得到一個錯誤(錯誤是在什麼我試過貼)

<?php 
$page = $_GET['page']; 
$screen_name = $_GET['screen_name']; 
$url = $_GET['url']; 
$post_data = $HTTP_RAW_POST_DATA; 

$header[] = "Content-type: text/xml"; 
$header[] = "Content-length: ".strlen($post_data); 

$ch = curl_init("'url'?screen_name='$screen_name'&?page='$page'"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

if (strlen($post_data)>0){ 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
} 

$response = curl_exec($ch);  
$response_headers = curl_getinfo($ch);  

if (curl_errno($ch)) { 
    print curl_error($ch); 
} else { 
    curl_close($ch); 
    header('Content-type: ' . $response_headers['content-type']); 
    print $response; 
} 


?> 

錯誤信息:

The response is not a valid XML or a JSON string. 

Error on line 1 of document : The element type "meta" must be terminated by the matching end-tag "". Nested exception: The element type "meta" must be terminated by the matching end-tag "". 

回答

2

This Works

<?php 

$post_data = $HTTP_RAW_POST_DATA; 

$header[] = "Content-type: text/xml"; 
$header[] = "Content-length: ".strlen($post_data); 

$screen_name = $_GET['screen_name']; 
$page = $_GET['page']; 

$url = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=$screen_name&page=$page"; 

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

if (strlen($post_data)>0){ 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
} 

$response = curl_exec($ch);  
$response_headers = curl_getinfo($ch);  

if (curl_errno($ch)) { 
    print curl_error($ch); 
} else { 
    curl_close($ch); 
    header('Content-type: ' . $response_headers['content-type']); 
    print $response; 
} 
?> 

雖然如果你打算多打一個電話,你可能想要考慮在AS中構建請求字符串,並將整個字符串添加到域的末尾。

IE。

您可以將「1/statuses/user_timeline.xml?screen_name = brybam &?page = 1」等內容傳遞給單個參數。

而你的PHP會看起來像這樣...

$query= $_GET['query']; 
$url = "http://api.twitter.com/$query"; 

甚至更​​好,創建自己的服務API,使用您自己的API調用特定於您的應用程序。這樣,當twitter API發生更改時,您無需重新構建SWF。

+0

非常感謝很多! – brybam 2011-04-22 18:18:51