Googleドライブ(pdf、word、excel)にファイルをアップロードする必要があります.C#を使用してASP.NETでどのように行うことができますか?あなたは私にすべての通路を一歩一歩説明してくれますか?それが役立つことができれば、私は私の最後のテストコード置く:ファイルをGoogleドライブにアップロード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.GoogleAPI;
using System.Runtime.Serialization;
using System.IO;
using System.Web.Script.Serialization;
...
protected void Page_Load(object sender, EventArgs e)
{
GoogleConnect.ClientId = "my_client_id";
GoogleConnect.ClientSecret = "my_client_secret";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
GoogleConnect.API = EnumAPI.Drive;
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];
string json = GoogleConnect.PostFile(code, (HttpPostedFile)Session["File"], Session["Description"].ToString());
GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize<GoogleDriveFile>(json);
tblFileDetails.Visible = true;
lblTitle.Text = file.Title;
lblId.Text = file.Id;
imgIcon.ImageUrl = file.IconLink;
lblCreatedDate.Text = file.CreatedDate.ToString();
lnkDownload.NavigateUrl = file.WebContentLink;
if (!string.IsNullOrEmpty(file.ThumbnailLink))
{
rowThumbnail.Visible = true;
imgThumbnail.ImageUrl = file.ThumbnailLink;
}
}
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
}
protected void UploadFile(object sender, EventArgs e)
{
Session["File"] = FileUpload1.PostedFile;
Session["Description"] = txtDescription.Text;
GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.file");
}
}
public class GoogleDriveFile
{
public string Id { get; set; }
public string Title { get; set; }
public string OriginalFilename { get; set; }
public string ThumbnailLink { get; set; }
public string IconLink { get; set; }
public string WebContentLink { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
}
をしかし、私はこのエラーがあります:
- That’s an error.
Error: redirect_uri_mismatch
The redirect URI in the request, http://localhost:61360/Prova.aspx , does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com?project=831126948299 to update the authorized redirect URIs.
要求の詳細:
scope=https://www.googleapis.com/auth/drive.file redirect_uri=http://localhost:61360/Prova.aspx response_type=code client_id=831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com approval_prompt=auto access_type=offline
を私はリダイレクトページを挿入しましたが、それは私に同じエラーを与えた。
OAuthサイトに登録すると、アプリが承認されると、そのユーザーにリダイレクトするウェブページが表示されます。エラーメッセージには、 '' http:// localhost:61360/Prova.aspx''はあなたが登録したものではありません。 Google Appsに登録したURLは何ですか? – Neil
私はリダイレクトページを挿入しません...私はアプリケーションを作成し、私のプログラムでIDと秘密を使用しました。リダイレクトURLとして何を配置すればよいですか? –
多分私は説明することができます: "console.developers.google.com"では、 "資格"、 "IDクライアントOAuth 2.0"で私は作成した名前フィールドだけを入れました。 「コンセンサス製品の画面」では、メールアドレスと製品名が –