轉到下面來看看回答Facebook的訪問令牌 - 自動獲取令牌
我得到Facebook的訪問令牌罰款,但如果我有麻煩時,我想這個過程自動化。
如果我訪問這個URL是瀏覽器,我得到訪問令牌就好了。
例子:
我粘貼到瀏覽器並回車這一點。
接着,我會發送到這個頁面:
我改變了訪問令牌一塊所以它不是一個真正的令牌
中提琴訪問令牌!
我想要做的是複製相同的行爲與代碼。我越來越接近但並不完全在那裏。
我不斷收到user_denied錯誤。
%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_ &顯示=頁&語言環境= EN_US & logger_id = 786a3153-1d81-415c-8dca-f8fa8b0cd630
我將所有標題輸出到控制檯。這是我所關注的位置標題**
我認爲它與302重定向有關嗎?
ApplicationId = request.ClientId;
string permissions = "['ads_management', 'ads_read']";
var destinationURL = String.Format(
@"https://www.facebook.com/dialog/oauth?client_id={0}&scope={1}&redirect_uri=http://www.kb-demos.com/login_success.html&response_type=token",
ApplicationId,
permissions);
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(destinationURL);
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
myHttpWebRequest.AllowAutoRedirect = false;
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
//Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}", myHttpWebRequest.Headers); // my http headers
// Print the HTML contents of the page to the console.
var headers = myHttpWebResponse.Headers;
// output all the headers
foreach(var header in headers) {
Console.WriteLine(header.ToString() + ": " + headers[header.ToString()] + "\n");
}
#region
//Stream streamResponse = myHttpWebResponse.GetResponseStream();
//StreamReader streamRead = new StreamReader(streamResponse);
//Char[] readBuff = new Char[256];
//int count = streamRead.Read(readBuff, 0, 256);
//Console.WriteLine("\nThe HTML contents of page the are : \n\n ");
//while (count > 0)
//{
// String outputData = new String(readBuff, 0, count);
// Console.Write(outputData);
// count = streamRead.Read(readBuff, 0, 256);
//}
//// Close the Stream object.
//streamResponse.Close();
//streamRead.Close();
// Release the HttpWebResponse Resource.
#endregion
myHttpWebResponse.Close();
Console.ReadLine();
我得到一個user_denied錯誤在這裏。但在瀏覽器中,我獲得了一個完美的令牌。我無法弄清楚爲什麼。
中的位置標頭中的標頭似乎工作使用瀏覽器的時候。
可能的情況下,如果我不能得到上述工作: 我想知道是否有與API的瀏覽器?什麼事情我可以從命令行調用 - 傳遞一些參數 - 然後得到重定向URL解析變量?
你不應該爲「自動」這一點。刮臉Facebook頁面,並使用他們網站上的任何自動化工具,明確反對他們的服務承諾。 – CBroe
@Croro lmao。我不認爲你明白這個應用程序的目的是什麼。我擁有允許訪問此應用的帳戶。我只是在計劃的作業上運行此應用程序以獲得每日訪問令牌,因此我可以運行另一個我開發的應用程序,它可以爲許多客戶端每天獲取SEO報告,而不是通過前端爲每個客戶端手動登錄以下載這些報告。 – Radmation
@CBroe問題在於訪問令牌每60天過期一次。所以現在我已經實現了獲取訪問令牌的自動檢索,所以我不必再觸摸它了。加上API的一個主要原因是自動完成任務。我不是「刮」網站,我只是給一個應用程序訪問我的Facebook帳戶.. – Radmation