响应URL返回的是以前的Imgur图像URL,而不是当前图像URL

时间:2019-10-25 17:18:44

标签: c# imgur system.net

我建立了一个新的Unity项目,该项目使用C#和System.Net访问Imgur的API。我可以从任何地方将图像拖入应用程序,并且可以通过新应用程序的客户端ID将屏幕快照上传到Imgur。成功上传后,我可以获得相当数量的响应数据,但是响应中的URL总是过时1。如果我刚刚上传了屏幕截图D,则返回的URL将链接到屏幕截图C,等等。

以下是响应数据的样子:

enter image description here

这是我在所有尝试中得到的结果,其中包括使用w.UploadValuesAsync()以及尝试使用Imgur应用程序的Anonymous和OAuth2(无回调)版本。

这是我的大部分代码,它们来自from here

public void UploadThatScreenshot()
{
    StartCoroutine(AppScreenshotUpload());
}

IEnumerator AppScreenshotUpload()
{
    yield return new WaitForEndOfFrame();
    ScreenCapture.CaptureScreenshot(Application.persistentDataPath + filename);

    //Make sure that the file save properly
    float startTime = Time.time;
    while (false == File.Exists(Application.persistentDataPath + filename))
    {
        if (Time.time - startTime > 5.0f)
        {
            yield break;
        }
        yield return null;
    }

    //Read the saved file back into bytes
    byte[] rawImage = File.ReadAllBytes(Application.persistentDataPath + filename);

    //Before we try uploading it to Imgur we need a Server Certificate Validation Callback
    ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

    //Attempt to upload the image
    using (var w = new WebClient())
    {
        string clientID = "a95bb1ad4f8bcb8";
        w.Headers.Add("Authorization", "Client-ID " + clientID);
        var values = new NameValueCollection
         {
             { "image", Convert.ToBase64String(rawImage) },
             { "type", "base64" },
         };

        byte[] response = w.UploadValues("https://api.imgur.com/3/image.xml", values);
        string returnResponse = XDocument.Load(new MemoryStream(response)).ToString();

        Debug.Log(returnResponse);
    }
}

为什么我从w.UploadValues(...)返回的URL总是落后一个?

0 个答案:

没有答案
相关问题