0
我有這個代碼,它從Instagram加載圖像。使用Instagram的日期條件加載圖像
public string giveInstagramImage()
{
string strtagName = "Snowy";
string strAccessToken = "<<REDACTED>>";
string nextPageUrl = null;
string imageUrl = null;
do
{
WebRequest webRequest = null;
if (webRequest == null && string.IsNullOrEmpty(nextPageUrl))
webRequest = HttpWebRequest.Create(String.Format("https://api.instagram.com/v1/tags/{0}/media/recent?access_token={1}", strtagName, strAccessToken));
else
webRequest = HttpWebRequest.Create(nextPageUrl);
var responseStream = webRequest.GetResponse().GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
using (StreamReader reader = new StreamReader(responseStream, encode))
{
JToken token = JObject.Parse(reader.ReadToEnd());
var pagination = token.SelectToken("pagination");
if (pagination != null && pagination.SelectToken("next_url") != null)
{
nextPageUrl = pagination.SelectToken("next_url").ToString();
}
else
{
nextPageUrl = null;
}
var images = token.SelectToken("data").ToArray();
foreach (var image in images)
{
imageUrl = image.SelectToken("images").SelectToken("standard_resolution").SelectToken("url").ToString();
if (String.IsNullOrEmpty(imageUrl))
Console.WriteLine("broken image URL");
var imageResponse = HttpWebRequest.Create(imageUrl).GetResponse().GetResponseStream();
var imageId = image.SelectToken("id");
return imageUrl;
}
}
}
while (!String.IsNullOrEmpty(nextPageUrl));
return imageUrl;
}
當前Instagram API給了我前20張圖片。我需要做的是加載過去30天的所有圖像。
我們該怎麼做?
我以某種不同的格式獲得時間。如何以日期時間格式獲取它? – Happy
要將它轉換爲datetime:http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa –
那麼instagram在unixtimestamp中返回? did not瞭解使用哪個示例 – Happy