Upload video to youtube using c# winform "Invalid credentials" exception - c#

I am trying to upload a video to youtube using C# Winform and I always get to "Invalid credentials" exception.
I am using username and password of my gmail account: is this ok?
the application name - can it be anything? or I need register it somewhere?
I have created in http://code.google.com/apis/youtube/dashboard a developer key, do I need to do more activation in order to make this code work?
This is my code:
YouTubeRequestSettings settings;
YouTubeRequest request;
string devkey = "My DEV KEY";
string username = "MY GAMIL MAIL";
string password = "MY GAMIL PASSWORD";
settings = new YouTubeRequestSettings("SOME APPLICATION", devkey, username, password) { Timeout = -1 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/mp4");
Video createdVideo = request.Upload(newVideo);
return createdVideo.VideoId;

That overload takes an auth token, not a username and password.
If you want to hard-code your password (which is a terrible idea), you also need to pass a client name.

I have found this example that has very detailed steps to achieve upload to youtube and many other things in C#
http://www.cstruter.com/blog/313
Hope it helpts

Related

C# Facebook app / post on site

im very new with Facebook apps and read several threads for creating them, but I have some problems with it.
First of all what I want to do: I want to create a web application that is able to post pictures, text and links on a facebook page that is managed by me.
I used the Facebook C# SDK: here!
What I have:
string facebookPageId = "<my page id>";
string app_id = "<my app id>";
string app_secret = "<my app secret>";
string scope = "publish_stream,manage_pages";
var fb = new FacebookClient();
dynamic res = fb.Get("oauth/access_token", new
{
client_id = app_id,
client_secret = app_secret,
grant_type = "client_credentials"
});
var access_token = res.access_token;
dynamic messagePost = new ExpandoObject();
messagePost.access_token = access_token;
messagePost.link = "http://www.test.at";
messagePost.name = "Testbot";
messagePost.caption = "{*actor*} " + "hello this is a test";
messagePost.description = "[SOME_DESCRIPTION]";
FacebookClient app = new FacebookClient(access_token);
app.AppId = app_id;
app.AppSecret = app_secret;
try
{
var result = app.Post("/hrechttest" + "/feed", messagePost);
}
catch (Exception e)
{
}
Well the code runs without any exceptions but in the output window I get the following:
Exception thrown: 'Facebook.FacebookOAuthException' in Facebook.dll
The next problem is:
As I understood it you must link your facebook app with your facebook page, but when I want to do that I cant select the page:
So what I did wrong or missed?
publish_stream is deprecated since many years, publish_pages is the correct permission to post to a Page (as Page).
API reference: https://developers.facebook.com/docs/graph-api/reference/page/feed#publish
Make sure you are using a Page Token, not a User Token:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
How to create Page Apps is explained in the docs too: https://developers.facebook.com/docs/pages/tabs

google api v3 query google contacts .NET

I am trying to build a C# application that queries my google contacts,and prints them to console.
The email address is :bhmi12#gmail.com
excellent is the name of the google app.
I have two problems:
The First Problem every time i run the app i have to call:
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
surf to the URL and get a new AccessCode even that google claims u only have to do it once. and then u get an access token.
The second Problem is that this code doesnt work, when it goes to PrintAllContacts it failes under a wierd exception:
There is some error in your request thats all we know"(the google response
to my request).
Is this the right way to write the scope?
thanks very much.
The code:
{
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.ClientId = #"my id";
parameters.ClientSecret = #"my secret";
parameters.RedirectUri = #"urn:ietf:wg:oauth:2.0:oob";
parameters.ResponseType="code";
parameters.Scope = #"https://www.google.com/m8/feeds/contacts/bhmi12%40gmail.com/full";
//string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
parameters.AccessCode = #"";
try
{
OAuthUtil.GetAccessToken(parameters);
//OAuthUtil.RefreshAccessToken(parameters);
var contacts = new ContactsRequest(new RequestSettings("excellent", parameters));
PrintAllContacts(contacts);
}
catch (GDataRequestException e)
{
Console.WriteLine("Operation failed ({0}): {1}", e.Message, e.ResponseString);
}
}
No. The scope is the following constant string value that looks like a URL:
"https://www.googleapis.com/auth/contacts.readonly"
If you intend to modify the user's contacts, then use this instead:
"https://www.google.com/m8/feeds"
Reference: https://developers.google.com/google-apps/contacts/v3/#authorizing_requests_with_oauth_20

Error Uploading Video to YouTube

I am using following code to upload a video to YouTube.
It always gives following error.
The remote server returned an error: (403) Forbidden.
My Code is
YouTubeRequestSettings settings;
YouTubeRequest request;
string devkey = YouTubeDeveloperKey;
string username = YoutubeUserName;
string password = YoutubePassword;
settings = new YouTubeRequestSettings("VideoEditor", devkey, username, password) { Timeout = -1 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
Please do you have any idea about this error
As per the Youtube API V2 documentation, error 403 is an authorization error.
Most probably the username and password might be wrong.
My guess: Did you enable two step authentication on your Google account ?
If so, you must use an application-specific password.
Try to go to your youtube application via https://console.developers.google.com then select your application go to APIs and auth -> APIs.
It will display a list of multiple available APIs, click on Youtube Data API, and then click "enable". This will enable this API to be used by your app and most likely will solve your issue.

Proxy Authentication for Twitterizer2 in C#

Currently the Code i am using to update twitter status is as follows...
public static void SendMessage(string message)
{
try
{
tokens = new OAuthTokens();
tokens.AccessToken = "Some Token";
tokens.AccessTokenSecret = "Some Secret";
tokens.ConsumerKey = "Some Key";
tokens.ConsumerSecret = "Some CSecret";
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, message);
}
Please spoon feed me on how to authenticate myself for a proxy on 10.0.0.21 and port 3128 requesting for a username and password.
I am able to access the net and download webpages from C# application using the following code but am not able to update twitter from twitterizer due to this issue...
WebClient w = new WebClient();
WebProxy p = new WebProxy("10.0.0.21", 3128);
p.Credentials = new NetworkCredential("UserName", "Password");
w.Proxy = p;
string s = w.DownloadString(SomeUrl);
How to do the same in twitterizer2 package...? Its not taking from IE because Authentication is required for this proxy.
I am not sure of how to modify the configuration file. One more issue is i will not run this application always behind a proxy..mostly it will be run outside a proxy.
Please help. Thanks.
Twitterizer handles proxy settings in 3 ways. They are, in order that Twitterizer chooses which to use:
Every method has an optional parameters argument. They are all based on a single class that has a proxy property that allows you to provide a web proxy exactly the same way that you did in your example. This is good if you have a small amount of Twitter integration, but obviously not great for larger applications.
You can specify your proxy in your configuration file using the <defaultproxy> element. Good for whole applications, but unfortunately won't handle the use of authentication.
The default IE settings are used.
Since your proxy requires authentication, the only option is to specify the optional properties class to every method.
For example:
public static void SendMessage(string message)
{
try
{
tokens = new OAuthTokens();
tokens.AccessToken = "Some Token";
tokens.AccessTokenSecret = "Some Secret";
tokens.ConsumerKey = "Some Key";
tokens.ConsumerSecret = "Some CSecret";
WebProxy p = new WebProxy("10.0.0.21", 3128);
p.Credentials = new NetworkCredential("UserName", "Password");
StatusUpdateOptions options = new StatusUpdateOptions();
options.Proxy = p;
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, message, options);
}
}

Desktop Application for youtube(Login and update profile from a desktop appliaction)

Greetings,
Can someone help me with this? I am trying to make a desktop application for Youtube where user can Login and update his profile etc. I am doing following
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.YouTube;
//Send Connection Request //I am doing something wrong here
YouTubeRequestSettings settings = new YouTubeRequestSettings("example app", developerKey, username, password);
YouTubeRequest request = new YouTubeRequest(settings);
I don't know what to do next and
how can I ensure if username and password are right? Please help
Thank you
I'm doing the same, and what you did is correct. You just need to catch the Exception that occurs. My code:
Video newVideo = new Video();
newVideo.Title = textBoxTitle.Text;// "Smideo Generated Movie";
newVideo.Tags.Add(new MediaCategory("Travel", YouTubeNameTable.CategorySchema));
newVideo.Keywords = textBoxKeyWords.Text;
newVideo.Description = textBoxDescription.Text;
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("Test, Example",
YouTubeNameTable.DeveloperTagSchema));
try
{
createdVideo = request.Upload(newVideo);
}
catch(InvalidCredentialsException c)
{
doSomethingAboutInvalidCredentials(c);
}

Categories