使用ASP.NET的FQL-将PHP示例转换为.NET
有人知道VB或C.NET的等效代码是什么吗 下面的代码是在PHP中运行fql查询的示例,但需要在C或VB中为.NET提供示例或等效代码 谢谢你的帮助使用ASP.NET的FQL-将PHP示例转换为.NET,php,asp.net,facebook,Php,Asp.net,Facebook,有人知道VB或C.NET的等效代码是什么吗 下面的代码是在PHP中运行fql查询的示例,但需要在C或VB中为.NET提供示例或等效代码 谢谢你的帮助 <?php $app_id = 'YOUR_APP_ID'; $app_secret = 'YOUR_APP_SECRET'; $my_url = 'POST_AUTH_URL'; $code = $_REQUEST["code"]; //auth user if(empty($code)) { $dialog
<?php
$app_id = 'YOUR_APP_ID';
$app_secret = 'YOUR_APP_SECRET';
$my_url = 'POST_AUTH_URL';
$code = $_REQUEST["code"];
//auth user
if(empty($code)) {
$dialog_url = 'https://www.facebook.com/dialog/oauth?client_id='
. $app_id . '&redirect_uri=' . urlencode($my_url) ;
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
//get user access_token
$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
. $app_id . '&redirect_uri=' . urlencode($my_url)
. '&client_secret=' . $app_secret
. '&code=' . $code;
$access_token = file_get_contents($token_url);
// Run fql query
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()'
. '&' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
//display results of fql query
echo '<pre>';
print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';
// Run fql multiquery
$fql_multiquery_url = 'https://graph.facebook.com/'
. 'fql?q={"all+friends":"SELECT+uid2+FROM+friend+WHERE+uid1=me()",'
. '"my+name":"SELECT+name+FROM+user+WHERE+uid=me()"}'
. '&' . $access_token;
$fql_multiquery_result = file_get_contents($fql_multiquery_url);
$fql_multiquery_obj = json_decode($fql_multiquery_result, true);
//display results of fql multiquery
echo '<pre>';
print_r("multi query results:");
print_r($fql_multiquery_obj);
echo '</pre>';
?>
我将您提供的php代码转换为c,但由于api的可用性而未进行测试。希望这对你有帮助
我将您提供的php代码转换为c,但由于api的可用性而未进行测试。希望这对你有帮助
private string TestApp()
{
StringBuilder str = new StringBuilder();
string app_id = "YOUR_APP_ID";
string app_secrete = "YOUR_APP_SECRET";
string my_url = "POST_AUTH_URL";
string code="";
if(Request.Params["code"]!=null)
code = Request.Params["code"].ToString();
string dialog_url = "";
if(code !="")
{
dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" + app_id + "&redirect_uri=" + Server.UrlEncode(my_url);
str.Append("<script>top.location.href=" + dialog_url + "'</script>");
}
string token_url = "https://graph.facebook.com/oauth/access_token?client_id=" + app_id + "&redirect_uri=" + Server.UrlEncode(my_url) + "&client_secret=" + app_secrete + "&code=" + code;
string access_token = file_get_contents(token_url);
string fql_query_url = "https://graph.facebook.com/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()&" + access_token;
string fql_query_result = file_get_contents(fql_query_url);
string fql_query_obj = Newtonsoft.Json.JsonConvert.SerializeObject(fql_query_result, Newtonsoft.Json.Formatting.Indented);
str.Append("<pre>\n");
str.Append("Query Results: " + fql_query_obj);
str.Append("</pre>\n");
string fql_multiquery_url = "https://graph.facebook.com/fql?q={\"all+friends\":\"SELECT+uid2+FROM+friend+WHERE+uid1=me()\",my+name\":\"SELECT+name+FROM+user+WHERE+uid=me()\"}&" + access_token;
string fql_multiquery_result = file_get_contents(fql_multiquery_url);
string fql_multiquery_obj = Newtonsoft.Json.JsonConvert.SerializeObject(fql_multiquery_result, Newtonsoft.Json.Formatting.Indented);
str.Append("<pre>\n");
str.Append("multi query results: " + fql_multiquery_obj);
str.Append("</pre>\n");
return str.ToString();
}
protected string file_get_contents(string fileName)
{
string sContents = string.Empty;
string me = string.Empty;
try
{
if (fileName.ToLower().IndexOf("http:") > -1)
{ // URL
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
}
else
{ // Regular Filename
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
sContents = sr.ReadToEnd();
sr.Close();
}
}
catch { sContents = "unable to connect to server "; }
return sContents;
}