I want to send events to my google calendar account from asp.net application
Have a look at Google API Calendar
http://code.google.com/intl/nl-NL/apis/calendar/
http://code.google.com/intl/nl-NL/apis/calendar/data/2.0/developers_guide_dotnet.html#CreatingSingle
Create single-occurance event
EventEntry entry = new EventEntry();
// Set the title and content of the entry.
entry.Title.Text = "Tennis with Beth";
entry.Content.Content = "Meet for a quick lesson.";
// Set a location for the event.
Where eventLocation = new Where();
eventLocation.ValueString = "South Tennis Courts";
entry.Locations.Add(eventLocation);
When eventTime = new When(DateTime.Now, DateTime.Now.AddHours(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);
look at the API
Like Murph said in the comment, link to the guide for .Net API
Related
First thing first, I never used SDK before and I don't know what does token mean. I am searching for the most simple solution, if possible without SDK, without token, without FB App.
I have a button in my C# application and when the user clicks on it I want a popup window where the user can login to Facebook or if he is logged in he can push the share button in order to share the predefined content.
While searching on the internet I found this code:
var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new {
value = "ALL_FRIENDS",
};
parameters.targeting = new {
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = client.Post("me/feed", parameters);
But this example uses Facebook SDK and it needs token. I want a simple solution, without SDK, without FB APP. I want a simple popup with predefined text.
Is there any solution?
An access token is an opaque string that identifies a user, app, or page and can be used by the app to make graph API calls.
Access Tokens identifies an app ,user or page
Without creating an app from facebook and getting a token you cannot proceed in this case(c# application).
I have a website made with ASP.NET webform .NET 4.5 C#. This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). What I need :
Post just created thread(message) from specific part of the forum to the corsponding facebook wall.
Optional : Sync the forum thread on webpage with message/comments on the specific facebook page
I have looked at these guides :
http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API
http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
But im not sure that this is really the solution for me? I have tried to follow the guide but it does not look the same.
Edit :
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);
//result = client.Get("debug_token", new
//{
// input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
// access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
//});
//result = client.Get("oauth/access_token", new
// {
// client_id = ConfigurationManager.AppSettings["FacebookAppId"],
// client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
// grant_type = "client_credentials",
// //redirect_uri = "http://www.MyDomain.net/",
// //code = ""
// });
result = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
grant_type = "client_credentials"
});
client.AccessToken = result.access_token;
result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[IdOfFacebookPage]");
return false;
Approach to post to a facebook wall:
You need to register in facebook developer tools.
Create a app (fill a form).
Download FGT 5.0.480 (Facebook graph toolkit)
Reference FGT dlls in your web application.
FGT has methods to post to facebook wall but needs appId.
Use the app id of your app created in step 2.
To post to an user's wall through facebook, it is only possible through an app.
Try this asp .net app, which will allow you to post in your wall:
https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf
This will allow you to envision what you need.
Your app gets an appId with which you need to generate auth token.
Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around.
When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it.
Hope this gives you an idea on how to go about doing this.
You can then post into the user's wall.
For Banshee's below request using Facebook SDK for .NET:
userId - facebook user id, wall to post the message
This user should have added the app created by you in step 1 else it will say unauthorized access.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";
messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new {
client_id = "app_id",
client_secret = "app_secret",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
try
{
var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee..
Edit: How to get extended token by Banshee:
Please follow this post
By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?
Im surprised that this simple task was so hard to get running and that there was vary little help to get.
I am using "Google.GData.Calendar" API to add Events to the Google Calendar using c#. But there is time difference between the events created in my DB and Google Calendar.
Following is the Code to add an Event to Google Calendar using the Google.GData API:
public static void AddEventToGoogle()
{
//string timezone = "US Mountain Standard Time";
Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
try
{
GOAuthRequestFactory authFactory = new GOAuthRequestFactory("cl", "MyApp");
authFactory.ConsumerKey = ConfigurationManager.AppSettings["GConsumerKey"].ToString();
authFactory.ConsumerSecret = ConfigurationManager.AppSettings["GConsumerKeySecret"].ToString();
authFactory.Token = "xxxxxxxxxx";
authFactory.TokenSecret = "xxxxxx";
Google.GData.Calendar.CalendarService service = new Google.GData.Calendar.CalendarService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
EventEntry entry = new EventEntry();
entry.Title.Text = "Test Google Event Create";
entry.Content.Content = "Test Google Event Create";
entry.Notifications = false;
When eventTime = new When();
eventTime.AllDay = false;
eventTime.StartTime = new DateTime(2013, 5, 9, 8, 0, 0);
eventTime.EndTime = new DateTime(2013, 5, 9, 11, 0, 0);
entry.Times.Add(eventTime);
// Send the request and receive the response:
EventEntry insertedEntry = service.Insert(postUri, entry);
if (insertedEntry != null && !string.IsNullOrEmpty(insertedEntry.EventId))
{
//Get the insertedEntry.EventId
}
}
catch (GDataRequestException gre)
{
HttpWebResponse response = (HttpWebResponse)gre.Response;
}
}
But with the above code there is a time difference with the event I intended to create and the entry in the Google Calendar. The TimeZone I have in my Google Calendar is "(GMT-07:00) Mountain Time - Arizona". This is happening when i change the TimeZones of my Google Calendar to CST, PST,...
Please suggest a workaround for this situation or where do I need to specify the TimeZone while adding an event to Google Calendar.
Updated my question with the complete method i used to add an event
The GData library uses v2 of the Google APIs. I think you will need to migrate your code to v3 in order to get proper support for time zones on events.
For example, see this page which shows an example of creating a recurring event. (Switch to the ".NET" tab".
Here are some resources that may help you:
Migration Guide
What's new in v3 (it doesn't mention time zones though)
Client libraries (see the ".NET" tab)
I did look through your code and the reference guide to the v2 GData library. I only see TimeZone properties on the CalendarEntry, EventFeed, and EventQuery classes. Since you're not using any of those, I don't think it is possible in v2.
UPDATE
It is possible in the v2 API. You can pass a time zone in the ICAL formatted <gd:recurrence> tag. Take a look at the note following the example in this documentation.
However, it doesn't appear that it is exposed as a property of the EventEntry class in the .Net GData client library. So my recommendation stands - use the v3 api and client library.
I am creating an ASP.NET C# app that uploads videos to a YouTube Channel.
*I have already read through (to the best of my ability) the documentation at
The YouTube API Documentation
I have been able to successfully implement two examples of uploading a video to the YouTube channel using the sample code provided.
For example, using direct method (only the important code attached):
<!-- eja: import the google libraries -->
<%# Import Namespace="Google.GData.Client" %>
<%# Import Namespace="Google.GData.Extensions" %>
<%# Import Namespace="Google.GData.YouTube" %>
<%# Import Namespace="System.Net" %>
<!-- some more code -->
<%
// specify where to go to once authenticated
Uri targetUri = new Uri(Request.Url, "VideoManager.aspx");
// hide the link to authenticate for now.
GotoAuthSubLink.Visible = false;
// GotoAuthSubLink.Visible = true;
// look for a session var storing the auth token. if it's not empty
if (Session["token"] != null)
{
// go to the VideoManager link
Response.Redirect(targetUri.ToString());
}
else if (Request.QueryString["token"] != null)
{
// if we have the auth key in the URL, grab it from there instead
String token = Request.QueryString["token"];
// set the session equal to AuthSubUtil's calling the exchangeForSessionToken method
// returns the token and convert it to a string
Session["token"] = AuthSubUtil.exchangeForSessionToken(token, null).ToString();
Response.Redirect(targetUri.ToString(), true);
}
else
{
//no auth token, display the link and create the token by loading the google
// auth page
String authLink = AuthSubUtil.getRequestUrl(Request.Url.ToString(), "http://gdata.youtube.com", false, true);
GotoAuthSubLink.Text = "Login to your Google Account";
GotoAuthSubLink.Visible = true;
GotoAuthSubLink.NavigateUrl = AuthSubUtil.getRequestUrl(Request.Url.ToString(),"http://gdata.youtube.com",false,true);
}
<asp:HyperLink ID="GotoAuthSubLink" runat="server"/>
That's page one...it loads the google authentication screen. (see link to attached image ,it's safe, I just set up a new account here on stackOverflow and can't upload images yet).
Then it leads to a page with the upload mechanism...The uploading works I am not worried about that, but here is the snippet of code FYI.
// create an instance ot the YouTubeService class. passing the application name and my DEV KEY
YouTubeService service = new YouTubeService(authFactory.ApplicationName, **API_KEY**);
// retrieve the current session token as a string if any
authFactory.Token = HttpContext.Current.Session["token"] as string;
// incorporate the information into our service
service.RequestFactory = authFactory;
try
{
// a YouTubeEntry object is single entity within a videoFeed object. It generally contains info
// about the video. when uploading, we will assign the values that we received to the feed.
YouTubeEntry entry = new YouTubeEntry();
// aggregate all the initial descriptor information
entry.Media = new Google.GData.YouTube.MediaGroup();
entry.Media.Description = new MediaDescription(this.Description.Text);
entry.Media.Title = new MediaTitle(this.Title.Text);
entry.Media.Keywords = new MediaKeywords(this.Keyword.Text);
// process entry.Media.Categories to assign the category
MediaCategory category = new MediaCategory(this.Category.SelectedValue);
category.Attributes["scheme"] = YouTubeService.DefaultCategory;
entry.Media.Categories.Add(category);
// prepare the token used for uploading
FormUploadToken token = service.FormUpload(entry);
HttpContext.Current.Session["form_upload_url"] = token.Url;
HttpContext.Current.Session["form_upload_token"] = token.Token;
// construct the URL
string page = "http://" + Request.ServerVariables["SERVER_NAME"];
if (Request.ServerVariables["SERVER_PORT"] != "80")
{
page += ":" + Request.ServerVariables["SERVER_PORT"];
}
page += Request.ServerVariables["URL"];
HttpContext.Current.Session["form_upload_redirect"] = page;
Response.Redirect("UploadVideo.aspx");
The page UploadVideo.aspx is the actual upload form, and it works, so I am not concerned about that.
The alternate method is not the recommended method, as it's synchronous in nature, but it DOES avoid that login screen as it allows us to pass credentials to authenticate (it works as a web app)...again principal code attached below.
<%
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory(ServiceNames.YouTube, "TesterApp");
// Response.Write("serviceNames.youtube=" + ServiceNames.YouTube + "<br />");
YouTubeRequestSettings s = new YouTubeRequestSettings(authFactory.ApplicationName, **your API KEY**,**Your email account as a username**,**your password**);
YouTubeRequest request = new YouTubeRequest(s);
Video newVideo = new Video();
newVideo.Title = "test at 4:40";
newVideo.Tags.Add(new MediaCategory("Games", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
// newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag", YouTubeNameTable.DeveloperTagSchema));
// newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
newVideo.YouTubeEntry.setYouTubeExtension("location", "Somewhere,Someplace");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\IMG_1672.MOV",
"video/quicktime");
Video createdVideo = request.Upload(newVideo);
Response.Write("This will print out once the file is uploaded...indicates that the code is <i>synchronous</i>. The cursor spins around until done. go get a coffee then check the YouTube Channel");
%>
So basically the question that I am asking is - Is there a method that will upload a video to a YouTube Channel in ASP.NET C# code a) for a web application b) that I can pass credentials through the code to c) bypass the Google authentication screen seen above and d) without using OAuth and openID and a cert etc?
The App is for only a short campaign (November only) and I am happy to use the deprecated authSubUtil and a dev key and do not need to worry about oAuth 2.x or open ID (since authsubutil will deprecate in 2015 anyway).
Any Help is appreciated.
thanks
Edward
You would be best placed to use the ClientLogin authentication, where you can store a users username & password for their account and then use DirectUpload.
Direct Upload: https://developers.google.com/youtube/2.0/developers_guide_dotnet#Direct_Upload
ClientLogin: https://developers.google.com/youtube/2.0/developers_guide_protocol_clientlogin#ClientLogin_Authentication
Note client login is being deprecated, and they want you to use OAuth, however if you do it quickly you should be okay!
I have a web site facebook app. I can login and post to users wall.What I really want is when a user creates an image on my web site , he can create a notification on couple friends to take an action on the image. How can I do this ?
I have this code but I don't see a notification at my notification area ?
var f = new FacebookClient();
dynamic result = f.Get("oauth/access_token", new
{
client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_SECRET,
grant_type = "client_credentials"
});
var token = result.access_token as string;
var reqClient = new FacebookClient(token);
var args = new Dictionary<string, object>();
args["message"] = "Invitation to action message";
args["data"] = "Invitation to action data";
var reqResult = reqClient.Post("/" + facebookId.ToString() + "/apprequests", args);
The app generated request go to the bookmarks counter and not to the top notifications (with the globe image).
There's no way for an app to send that kind of notification to a user (that I'm aware of).
You can check in the Social Channels guide on the options that are available for you, also you can check the Requests documentation.
Use app notifications. The guide I've linked to shows a lot of documentation.