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