Visual Studio 2010 Framework 4.0
I am trying to insert a job using Google coordinate API.For inserting job I tried two ways.Using webrequest and coordinate API.But I am not able to insert the job. Using Google Coordinate API:Getting error"Authentication doesn't exist in namespace google.api"
I installed google coordinate API using nuget.I used below code for inserting job using coordinate API.But I am getting error on “GoogleAuthenticationServerDescription” line Error:”GoogleAuthenticationServerDescription doesn't exist in current context”.
Note: I had imported Google.Api namespace but I didn't found
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 = "user@example.com";
//Create the Job
JobsResource.InsertRequest
ins1=service.Jobs.Insert(jobBody,"TeamID","Address",17.854425,75.51869,"Test");
================================================================================
Web request code for inserting job:In this scenario I am getting a error like 401(unauthorized). I am confused how to pass outh access token using web request.
Here is the code:
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();