我試圖使用C#Facebook SDK檢索相冊的ID。但是我收到以下錯誤:訪問任務的結果屬性
System.Threading.Tasks.Task' does not contain a definition for 'Result' and no extension method 'Result' accepting a first argument of type 'System.Threading.Tasks.Task' could be found
請看下面的代碼,就在foreach線
try
{
string wallAlbumID = string.Empty;
FacebookClient client = new FacebookClient(accessToken);
client.GetTaskAsync(pageID + "/albums")
.ContinueWith(task =>
{
if (!task.IsFaulted)
{
foreach (dynamic album in task.Result.data)
{
if (album["type"] == "wall")
{
wallAlbumID = album["id"].ToString();
}
}
}
else
{
throw new DataRetrievalException("Failed to retrieve wall album ID.", task.Exception.InnerException);
}
});
return wallAlbumID;
}
爲了記錄發生錯誤,則FacebookClient.GetTaskAsync
方法返回Task<object>
如果你調試代碼,並期待在運行時類型的「任務」,你會發現它是任務型的衍生物,你可能只是需要做一個演員,如'((SomeFacebookTaskType)任務).Result' – joshuahealy