Visual Studio 2010中 框架4.0無法創建使用谷歌協調工作服務
我嘗試使用谷歌的API。有關協調工作插入我試圖插入一個作業二都ways.Using的WebRequest和協調API.But我我無法插入這份工作。 使用谷歌API座標:我安裝谷歌協調使用nuget.I API下面的代碼用於使用座標API.But我上「收到錯誤插入的工作得到錯誤「驗證在名字空間不存在google.api」
GoogleAuthenticationServerDescription「行 錯誤:」GoogleAuthenticationServerDescription在當前上下文中不存在「。
注:我已經進口了Google.Api命名空間,但我沒有發現
Authentication.OAuth2.DotNetOpenAuth in namespace.
var provider = new WebServerClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier =」MyclientID」;
provider.ClientSecret = 「MySecretID;
var auth = new OAuth2Authenticator<WebServerClient>(provider, GetAuthorization);
var service = new CoordinateService(new BaseClientService.Initializer());
Job jobBody = new Job();
jobBody.Kind = "Coordinate#job";
jobBody.State = new JobState();
jobBody.State.Kind = "coordinate#jobState";
jobBody.State.Assignee = "[email protected]";
//創建工作
JobsResource.InsertRequest
INS1 = service.Jobs.Insert(jobBody,「TeamID 」, 「地址」,17.854425,75.51869, 「測試」);
============================================== ==================================
插入作業的Web請求代碼:在這種情況下,我是得到像401(未經授權)的錯誤。我很困惑如何使用web請求傳遞訪問令牌。
下面是代碼:
double latitude = Convert.ToDouble(tbLatitude.Text);
double longitude = Convert.ToDouble(tbLogitude.Text);
String appURL = "https://www.googleapis.com/coordinate/v1/teams/TeamID/jobs/";
string strPostData = String.Format("teams={0},&job={1}&address={2}&lat=
{3}&lng={4}&title={5}&key={6}",tbTeamID.Text, "?", tbAddress.Text, latitude,
longitude, tbTitle.Text,"APIKEY");
HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as HttpWebRequest;
wrWebRequest.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteData = encoding.GetBytes(strPostData);
wrWebRequest.ContentLength = strPostData.Length;
wrWebRequest.ContentType = "application/json";
wrWebRequest.UserAgent = "MyApplication/1.0";
wrWebRequest.Referer = "https://www.googleapis.com/coordinate/v1/teams/teamId/jobs";
// Post to the registration form.
StreamWriter objswRequestWriter = new
StreamWriter(wrWebRequest.GetRequestStream());
objswRequestWriter.Write(strPostData);
objswRequestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse =
(HttpWebResponse)wrWebRequest.GetResponse();
StreamReader objsrResponseReader = new
StreamReader(hwrWebResponse.GetResponseStream());
string strResponse = objsrResponseReader.ReadToEnd();
我會檢查谷歌.net客戶端庫和更新。我在原來的評論中沒有提到,使用Web請求的原因是,如果成功的話,我可以在MS Access VBA代碼中實現。 – 2014-10-06 07:02:00
你不能用.NET客戶端庫來做這件事嗎? – peleyal 2014-10-06 15:38:14
使用.Net客戶端庫示例代碼時,我得到(;)期望錯誤,同時確認憑據變量 – 2014-10-07 05:24:23