/// <summary> /// Sends a request to revoke the access token. /// </summary> /// <param name="accessToken">May contain an access token, which should be revoked.</param> /// <exception cref="NotSupportedException"> /// <para>Provider does not support revoking the access token, or the method is not implemented.</para> /// <para>Use the property <see cref="OAuthBase.SupportRevokeToken"/>, to check the possibility of calling this method.</para> /// </exception> /// <remarks> /// <para>If <paramref name="accessToken"/> parameter is not specified, it will use the current access token from the same property of the current class instance.</para> /// </remarks> public override RequestResult RevokeToken(AccessToken accessToken = null) { accessToken = base.GetSpecifiedTokenOrCurrent(accessToken); return(OAuthUtility.Delete ( "https://graph.facebook.com/v2.7/me/permissions", new NameValueCollection { { "access_token", accessToken.Value } } )); }
public ActionResult Yandex(string method) { try { if (Session["Yandex:AccessToken"] == null) { throw new Exception(Test.Resources.Strings.SessionIsDead); } // get access token from session var token = (OAuth2AccessToken)Session["Yandex:AccessToken"]; RequestResult result = null; string auth = String.Format("OAuth {0}", token.Value); if (method == "upload") { #region upload file to Yandex.Disk // checking whether the folder exists try { result = OAuthUtility.Get ( endpoint: "https://cloud-api.yandex.net/v1/disk/resources", parameters: new HttpParameterCollection { { "path", "/Nemiro.NET" } }, authorization: auth ); } catch (RequestException ex) { // error if (ex.StatusCode == 404) { // create folder // help: https://tech.yandex.ru/disk/api/reference/create-folder-docpage/ (sorry, russian only) result = OAuthUtility.Put ( endpoint: "https://cloud-api.yandex.net/v1/disk/resources/", parameters: new HttpParameterCollection { new HttpUrlParameter("path", "/Nemiro.NET") }, authorization: auth ); if (result.StatusCode != 201) { // error throw new Exception(String.Format("HTTP{0}: {1}", result.StatusCode, Regex.Unescape(result.ToString()))); } } else { // other error throw new Exception(String.Format("HTTP{0}: {1}", ex.StatusCode, Regex.Unescape(ex.RequestResult.ToString()))); } } catch (Exception ex) { // other error throw ex; } InitTestFiles(); // help: https://tech.yandex.ru/disk/api/reference/upload-docpage/ (sorry, russian only) // get url for uploading result = OAuthUtility.Get ( endpoint: "https://cloud-api.yandex.net/v1/disk/resources/upload", parameters: new HttpParameterCollection { new HttpUrlParameter("path", "/Nemiro.NET/Nemiro.OAuth.zip"), new HttpUrlParameter("overwrite", "true") }, authorization: auth ); // success if (result.StatusCode == 200) { // send file result = OAuthUtility.Put ( endpoint: result["href"].ToString(), parameters: HttpContext.Cache["Nemiro.OAuth"] as byte[] // content of the file from cache ); #region and copy my new music album :) try { // exists? var result2 = OAuthUtility.Get ( endpoint: "https://cloud-api.yandex.net/v1/disk/resources", parameters: new HttpParameterCollection { { "path", "/Загрузки/Aleksey Nemiro - Combination" } }, authorization: auth ); } catch (RequestException ex) { try { // no exists if (ex.StatusCode == 404) { // copy OAuthUtility.Post ( endpoint: "https://cloud-api.yandex.net/v1/disk/public/resources/save-to-disk/", parameters: new HttpParameterCollection { new HttpUrlParameter("public_key", "https://yadi.sk/d/vsccXxJscnsPX"), new HttpUrlParameter("name", "Aleksey Nemiro - Combination") }, authorization: auth ); } } catch { } } catch { } #endregion return(Content("Successfully!\r\n\r\nPlease look for \"/Nemiro.NET/Nemiro.OAuth.zip\" in your Yandex.Disk.", "text/plain")); } #endregion } else if (method == "delete") { #region delete uploaded file result = OAuthUtility.Delete ( endpoint: "https://cloud-api.yandex.net/v1/disk/resources/", parameters: new HttpParameterCollection { new HttpUrlParameter("path", "/Nemiro.NET"), new HttpUrlParameter("permanently", "true") }, authorization: auth ); #endregion } else { #region other methods string url = "https://cloud-api.yandex.net/v1/disk/"; if (method == "disk-resources") { url = "https://cloud-api.yandex.net/v1/disk/resources?path=/"; } else if (method == "albums") { url = String.Format("http://api-fotki.yandex.ru/api/users/{0}/albums/", Session["Yandex:UserName"]); } // execute the request result = OAuthUtility.Get(endpoint: url, authorization: auth); #endregion } return(Content(result.ToString(), "text/plain")); } catch (Exception ex) { return(Content(ex.ToString(), "text/plain")); } }