I have based the following on this article here;
http://code.google.com/googleapps/marketplace/tutorial_dotnet.html#Integrate-OAuth
I am trying to use OAuth to validate a user - and (for the moment) make a
call to Google to retrieve Calendar events
When the user clicks the following button
<asp:ImageButton ID="GoogleLogin"
runat="server"
OnCommand="GoogleLogin_Click"
CommandArgument="https://www.google.com/accounts/o8/id"
ImageUrl="~/Images/Google32x32.png"
AlternateText="Login with your Google account"
style="position:absolute; top:5px; left:40px;" />
The application runs the following code;
protected void GoogleLogin_Click(object src, CommandEventArgs e)
{
String GoogleOPIndentifier = String.Empty;
OpenIdRelyingParty openid = null;
UriBuilder uriBuilder = null;
FetchRequest fetch = null;
try
{
GoogleOPIndentifier = e.CommandArgument.ToString();
openid = new OpenIdRelyingParty();
uriBuilder = new UriBuilder(Request.Url) { Query = "" };
IAuthenticationRequest req =
openid.CreateRequest(GoogleOPIndentifier, uriBuilder.Uri, uriBuilder.Uri);
fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
req.AddExtension(fetch);
req.RedirectToProvider();
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (openid != null) openid.Dispose();
openid = null;
fetch = null;
uriBuilder = null;
GoogleOPIndentifier = String.Empty;
}
}
This seems to work fine, when the user clicks on the button, the application
redirects to Google and returns.When it does the following code is executed.
try
{
OIDRP = new OpenIdRelyingParty();
var authenticationResponse = OIDRP.GetResponse();
if (authenticationResponse != null)
{
switch (authenticationResponse.Status)
{
case AuthenticationStatus.Authenticated:
HasLoggedIn.Visible = true;
HasNotLoggedIn.Visible = false;
YourAccount.Visible = true;
var fetch =
authenticationResponse.GetExtension<FetchResponse>();
Session["Identifier"] =
authenticationResponse.ClaimedIdentifier.ToString();
// fetch attributes
email =
fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
firstName =
fetch.GetAttributeValue(WellKnownAttributes.Name.First).Trim();
lastName =
fetch.GetAttributeValue(WellKnownAttributes.Name.Last).Trim();
WelcomeLabel.Text = "Welcome " + firstName + "
" + lastName;
WelcomeLabel.Visible = true;
// get events test code: Objectivfy once
alogorythm determined
consumerKey =
RoleEnvironment.GetConfigurationSettingValue("GoogleConsumerKey");
consumerSecret =
RoleEnvironment.GetConfigurationSettingValue("GoogleConsumerSecret");
calendar = new
Google.Calendar(Application_Name, consumerKey, consumerSecret);
EventFeed feed = getCalendarEvents(email,
"full", true, 3);
break;
case AuthenticationStatus.Canceled:
HasLoggedIn.Visible = false;
HasNotLoggedIn.Visible = true;
YourAccount.Visible = false;
break;
case AuthenticationStatus.Failed:
HasLoggedIn.Visible = false;
HasNotLoggedIn.Visible = true;
YourAccount.Visible = false;
break;
}
}
else
{
WelcomeLabel.Visible = false;
YourAccount.Visible = false;
}
}
catch (System.Exception ex)
{
Session["ErrorMessage"] = ex.Message;
Response.Redirect("Error.aspx");
}
finally
{
}
This code in turn makes a call to getCalendarEvents;
private EventFeed getCalendarEvents(string requestorId, string
projection, bool singleEvents, int maxResults)
{
// Create an OAuth factory to use
GOAuthRequestFactory requestFactory = new
GOAuthRequestFactory("cl", Application_Name);
// Available from vendor profile page (next to each application)
// when logged into the Marketplace
requestFactory.ConsumerKey =
RoleEnvironment.GetConfigurationSettingValue("GoogleConsumerKey");
requestFactory.ConsumerSecret =
RoleEnvironment.GetConfigurationSettingValue("GoogleConsumerSecret");
// Create the CalendarService and set its RequestFactory
CalendarService service = new CalendarService(Application_Name);
service.RequestFactory = requestFactory;
service.SetAuthenticationToken(Session["Identifier"].ToString());
// Query the service with the parameters passed to the function
EventQuery query = new EventQuery();
query.Uri = new
Uri("https://www.google.com/calendar/feeds/default/private/" + projection);
query.OAuthRequestorId = requestorId;
query.NumberToRetrieve = maxResults;
query.SingleEvents = singleEvents;
query.StartTime = DateTime.Now;
query.SortOrder = CalendarSortOrder.ascending;
EventFeed resultFeed = service.Query(query);
return resultFeed;
}
}
The thing is when it makes the call to service.Query(query) I get the following
error;
Execution of request failed:
https://www.google.com/calendar/feeds/default/private/full?max-results=3&[email protected]&start-min=2011-08-25T21:22:20Z&sortorder=ascending&singleevents=true
But I don't seem to have any clue as to what caused the execution to
actually fail.
Any ideas what I am missing.
Thanks in advance
--
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html