Adding an Event to a "specific" Google Calender with GData API - c#

I'm trying to add an event to a specific calendar in google calendar and I just don't find how. Here's my code :
CalendarService service = new CalendarService("MyTEst");
service.setUserCredentials("Username", "Password");
EventEntry entry = new EventEntry();
// Set the title and content of the entry.
entry.Title.Text = "title";
entry.Content.Content = "test";
// Set a location for the event.
Where eventLocation = new Where();
eventLocation.ValueString = "Location";
entry.Locations.Add(eventLocation);
When eventTime = new When(DateTime.now, DateTime.now.AddDays(2));
entry.Times.Add(eventTime);
Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");
// Send the request and receive the response
AtomEntry insertedEntry = service.Insert(postUri, entry);
Can anyone help me out with this one?
Edit
Maybe I should mention that this fonctionnability is only accessible for an administrator of a site which want to easly add rendez-vous and note to his google calendar so I automaticaly authenticated it with "hardcoded" value so I'm sure the username and password are ok.

Your code is working with the default Google Calendar for your specified user name and password. (IE it is using the default calendar for username#gmail.com) You can see this because the URI points to "/feed/default/private". If you want to post the event to another calendar the user name must authorized to post to that calendar, and you need to post to THAT calendars private uri.
EDIT:
The default format of this private URL is "http://www.google.com/calendar/feeds/CALENDAR_ID/private/full"
To find the calendar id, it is next Calendar Address in the calendar settings page on Google Calendars. It will appear similar to this:
"***************************#group.calendar.google.com"
The final URL would be:
EDIT:
"http://www.google.com/calendar/feeds/***************************#group.calendar.google.com/private/full"
This will go in your Uri postUri = new Uri();
EDIT:
My mistake was that I mentioned that you need to also include the private key after the word private. You do not actually have to do this. I have verified that I could successfully post to a secondary calendar by removing the private key.

Related

how to add additional query after link path

I am sending link to email address for password reset functionality and after sometime i want this link to expire. for that i have created a token(which is encrytped using a key) and expire-date and i want to put these as query in my email link but i don't know to do it.
this is how i use token class in forgotPassword Post method.
var tokenModel = new LinkExpire();
tokenModel.ExpiresOn = DateTime.Now.AddSeconds(10);
tokenModel.CreateToken = TokenHelperMethods.GetToken(tokenModel);
this is my link code.
string resetCode = Guid.NewGuid().ToString();
var varifyUrl = "/E_HealthCare_Web/Account/ResetPassword/" + resetCode;
var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, varifyUrl);
and in my email body i am sending link like this
"<br/> <br/> <a href = '" + link +"&expire="+tokenModel.ExpiresOn+"&token="+tokenModel.CreateToken+"'>Reset link</a> <br/><br/>" +
which does not to work as expected. anyone can help me achieve this, also i am not using core, only mvc5.
Edit this is my controller where i am recieving link values
public ActionResult ResetPassword(string id, DateTime expire, string token)
while clicking on link gives A potentially dangerous Request.Path value was detected from the client (&) error.
Here is my suggestion, instead of adding expiration token query parameters with URL manage this at your method action level i.e.
You already have the information that which login is going to this URL. All you have to do is that before sending this URL via email, make a separate temp table that will have user ID, reset password URL path, created date/time column (this column will mange the data/time when you send the URL to the user for password reset) and active/Iactive status column.
Now at code level when this particular URL is hit by user, first get the active row only entry against this URL & user ID and get the created date/time column value.
Check the difference between the active created date/time column and current date/time.
if difference between two dates is more than 24hr send expiration response otherwise change the password.
Mark that entry as inactive.
Know that against each user the active entry in this new table exist only when user request's password reset, otherwise all existing entries are marked as inactive.
You can delete instead of active/inactive as well. this is temp table.

How to assign site for new user via Kentico API

I'm trying to create a new Kentico user and assigning them to a site, via Kentico API: https://docs.kentico.com/api11/configuration/users#Users-Assigningausertoasite
In my case SiteContext.CurrentSiteName returns empty string. I thought of trying by hard coding the site.
UserInfor newUser = new UserInfo();
//...set all required properties...
//add user to site
UserInfoProvider.AddUserToSite(newUser.UserName, "My Site Code(or Display) Name");
//save user
UserInfoProvider.SetUserInfo(newUser);
Tried both Display Name as well as Code Name of the site in UserInfoProvider.AddUserToSite, but the user is not getting assigned to the site on Kentico site. It does get created with all the properties.
You have to use SiteInfoProvider to get the site code name
var si = SiteInfoProvider.GetSites()
.WhereEquals("SiteId",123)
.FirstOrDefault();
UserInfoProvider.AddUserToSite(newUser.UserName, si.SiteName);
Just had to add user to the site after saving the user.
//save user
UserInfoProvider.SetUserInfo(newUser);
//add user to site
UserInfoProvider.AddUserToSite(newUser.UserName, "My Site Code Name (not display name)");

Using the Windows Facebook SDK the FBUser class misses information

Using the Windows SDK for Facebook I've managed to log in and set the correct permissions to retrieve some info.
This was done using this code
FBSession sess = FBSession.ActiveSession;
sess.FBAppId = FBAppId;
sess.WinAppId = WinAppId;
// Add permissions
sess.AddPermission("public_profile");
// Do the login
await sess.LoginAsync();
Now the problem is that I can only retrieve a small bit of information from the FBUser and not all the fields that exists within it, for example:
sess.User.Name; // This WORKS
sess.User.Id; // This WORKS
sess.User.FirstName; // DOESN'T WORK
sess.User.LastName; // DOESN'T WORK
sess.User.Locale; // DOESN'T WORK
...
The FBUser associated with the ActiveSession is from the beginning ONLY populated with the data that you get from the initial "did login work"-request (which is a standard request to the /me Uri).
This only includes:
Full Name
Facebook ID
To get more data about the user you need to make use of the Graph API, and include the fields you're interested in as a parameter in the request.
This is one example how it could look like to update the current FBUser with the first_name, last_name and locale of the user.
// This is the current user that we're going to add info to
var currentUser = FBSession.ActiveSession.User;
// Specify that we want the First Name, Last Name and Locale that is connected to the user
PropertySet parameters = new PropertySet();
parameters.Add("fields", "locale,first_name,last_name");
// Set Graph api path to get data about this user
string path = "/me/";
// Create the request to send to the Graph API, also specify the format we're expecting (In this case a json that can be parsed into FBUser)
FBSingleValue sval = new FBSingleValue(path, parameters,
new FBJsonClassFactory(FBUser.FromJson));
// Do the actual request
FBResult fbresult = await sval.Get();
if (fbresult.Succeeded)
{
// Extract the FBUser with new data
var extendedUser = ((FBUser)fbresult.Object);
// Attach the newly fetched data to the current user
currentUser.FirstName = extendedUser.FirstName;
currentUser.LastName = extendedUser.LastName;
currentUser.Locale= extendedUser.Locale;
}
Please note that the sample code only includes a very minimum amount of verification. Since this includes network calls more should be added.

C# Facebook SDK - How to use web forms to server side authorize canvas application

There are lots of sample applications in MVC but the current project I'm working on requires that I use web forms.
I can authorize the application using the javascript method but I want to use server side. Below is what I started with on the page.load
dynamic parameters = new ExpandoObject();
parameters.client_id = AppId;
parameters.client_secret = appSecret;
parameters.response_type = "code";
//parameters.state = state;
parameters.redirect_uri = "http://fb.local/page.aspx";
// The requested response: an access token (token), an authorization code (code), or both (code token).
parameters.response_type = "token";
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
//parameters.display = "popup";
// add the 'scope' parameter only if we have extendedPermissions.
if (!string.IsNullOrWhiteSpace(ExtendedPermissions))
parameters.scope = ExtendedPermissions;
// generate the login url
var fb = new FacebookClient();
var loginUrl = fb.GetLoginUrl(parameters);
Response.Redirect(loginUrl.AbsoluteUri, true);
I can authorize but I'm not able to get the access token from the URL.
On the next page I can view source and see the access token in the url bar but I'm not sure how to go about getting it into the code. once I have the token, I'm all set.
page.aspx#access_token=AAACrxQhmdpY
I used to this code on my page load and works, its not a very clean code, but you may figure out how to change it for your best use. so the algorithm is that when the page loads you redirect the user to Facebook authentication page using response.redirect to a string that contains three parameters:your app ID(appid), what permissions you are asking your user(scope), where you want Facebook to redirect the user after authorization, and a parameter as state which i guess it should be a random number. so after the user authorized your application he/she will be redirected to your page, with a request URL that contains the same state you prepared Facebook with(and you can use to identify who which request was which if there are many requests i guess) and also a new "code" parameter which you pass on to Facebook to obtain access token, you can use Facebook c# sdk to obtain the access token.in my code there is a line that says "if code is not null, go to alireza" and alireza is a line tag after the response.redirect code, this is because you dont want the process to be repeated all over and over (and of course probably the browser show an error).
int intstate;
string strstate;
string redirecturltofb;
string scope;
string appid;
code = Request.QueryString["code"];
if (!String.IsNullOrWhiteSpace(code))
{
goto alireza;
}
appid = "424047057656831";
scope = "user_about_me,user_activities,user_groups,email,publish_stream,user_birthday";
intstate = 45;
strstate = Convert.ToString(intstate);
redirecturltofb = "https://www.facebook.com/dialog/oauth?client_id=" + appid + "&redirect_uri=http://test5-2.apphb.com/&scope=" + scope + "&state=" + strstate;
Response.Redirect(redirecturltofb);
You have to use Javascript SDK to get access token back to code behind.
Use FB.Init as in http://csharpsdk.org/docs/web/getting-started
and do post back on certain conditions to get the access token.
Thank you,
Dharmendra

EWS API - Create calendar and share with reviewer permissions

I'm having some trouble on creating and share a calendar with review permissions using Exchange Webservice API .NET.
At the moment this is my code:
Folder addCalendar = new Folder(service);
addCalendar.DisplayName = name;
addCalendar.FolderClass = "IPF.Appointment";
var perm = new FolderPermission(new UserId("reviewer#test.com"),
FolderPermissionLevel.Reviewer);
addCalendar.Permissions.Add(perm);
addCalendar.Save(WellKnownFolderName.MsgFolderRoot);
The calendar is created, in my account I can see the calendar and the user 'reviewer#test.com' has the correct permissions.
The problem is: The calendar doesn't show at the reviewer's account.
You have to do two things:
Set the appropiate permissions:
var folder = Folder.Bind(service, WellKnownFolderName.Calendar);
folder.Permissions.Add(new FolderPermission("someone#yourcompany.com",
FolderPermissionLevel.Reviewer));
folder.Update();
Then, send an invitation message. Now, this is the hard part. The message format is specifified in [MS-OXSHARE]: Sharing Message Object Protocol Specification. The extended properties are defined in [MS-OXPROPS]: Exchange Server Protocols Master Property List. You need to create a message according to that specification and send it to the recipient.
EDITED:
To set the sharing properties on the element, use extended properties.
First, define the properties. For example, the PidLidSharingProviderGuidProperty is defined as follows:
private static readonly Guid PropertySetSharing = new Guid("{00062040-0000-0000-C000-000000000046}");
private static readonly ExtendedPropertyDefinition PidLidSharingProviderGuidProperty = new ExtendedPropertyDefinition(PropertySetSharing, 0x8A01, MapiPropertyType.CLSID);
private static readonly ExtendedPropertyDefinition ConversationIdProperty = new ExtendedPropertyDefinition(0x3013, MapiPropertyType.Binary);
You can then set the property on a new item using the SetExtendedProperty method:
item.SetExtendedProperty(PidLidSharingProviderGuidProperty, "somevalue");
I figured out how to programmatically send a sharing invitation within an organization through EWS. May not answer all your questions, but it's a good start to understanding how in-depth you gotta get to actually do it. Heres the link

Categories

Resources