In C#, I'm uploading a video file to Facebook from a server, using the following method:
string fullurl = "https://graph-video.facebook.com/me/videos?" + "title=" + title + "&access_token=" + accessToken;
WebClient client = new WebClient();
byte[] returnBytes = client.UploadFile(fullurl, path);
path is the path to the video file on the server. This works, and shows a video uploaded post on the user profile. How can I add a text description (with link) and action links to that post?
please keep the answers in C#
you should pass extra query string parameter - description - with embedded URL. Something like this:
var description = "Bring your conversations to life on Facebook. With face-to-face video calling, now you can watch your friends smile, wink and LOL.\n\nTo get started, visit http://www.facebook.com/videocalling";
string fullurl = string.Format("https://graph-video.facebook.com/me/videos?title={0}&description={1}&access_token={2}", HttpUtility.UrlEncode(title), HttpUtility.UrlEncode(description ), accessToken);
I did it. Following is my code:
string a = "User_Access_Token";
string fullurl = string.Format("https://graph-video.facebook.com/me/videos?title={0}&description={1}&access_token={2}", HttpUtility.UrlEncode("Dulha"), HttpUtility.UrlEncode("hello"), a);
WebClient client = new WebClient();
byte[] returnBytes = client.UploadFile(fullurl, #"C:\Users\Users\Downloads\Dulha.mp4");
Related
I am trying to make for example a simple weather app. Mine is for an Air Quality API.
I had this code but I didn't think it would work with JSON.
var webClient = new WebClient();
...
var text = e.Result; // get the downloaded text and store in this variable
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "downloaded.txt"; // local file to save text in
string localPath = Path.Combine(documentsPath, localFilename); // local path to save file to
File.WriteAllText(localPath, text); // writes to local storage
myTextView.Text = text; // updates the TextView element on the screen with downloaded text data
Then Just
var url = new Uri("https://api.breezometer.com/baqi/?lat=" + latitude + "&lon=" + longitude +"&key=YOUR KEY HERE");
webClient.Encoding = Encoding.UTF8;
webClient.DownloadStringAsync(url);
Im just not sure of the encoding method for JSON.
If anyone knows please answer thanks...
Use the WebClient class in System.Net:
var json = new WebClient().DownloadString("url");
Origin answer:
How to get a json string from url?
Assume that I have a php script which saves get queries on info parameter. I have it as a string variable:
string url = "http://example.com/write.php?info="
Let's say I have a string like this:
string info = "asd";
So I want to load the web page without showing to user. The url will be url+info
How can i do that?
You can use WebClient:
var fullUrl = url + info;
var conent = new System.Net.WebClient().DownloadString(fullUrl);
as the title ! Who can help me this problem ?
thanks!
i tried code:
HtmlDocument put = this.webBrowser1.Document;
put.GetElementById("input").SetAttribute("value", "abc");
i can see element username but password unknow element???
but not work for me! :(
The right way to do this would be to send an automated post request to the server with the parameters that you have specified. You will get HTML in return that you can parse then.
Use WebClient for this.
Here is an example:
string URI = "http://www.server.com/login";
string myParameters = "username=value1&password=value2";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
My Code for Downloader uses two textboxes :
Two get user URL
To specify the drive
private void downloadbtn_Click(object sender, EventArgs e)
{
WebClient myWebClient = new WebClient();
//Declarations for string objects
string downloadURL, path;
//raw URL taken from user
downloadURL = this.downloadURL.Text;
path = savePath.Text;
Uri tmp = new Uri(downloadURL);
string EndPathFileName = tmp.Segments.Last();
path = path + #"\" + EndPathFileName;
//downloads file using async method
myWebClient.DownloadFileAsync(tmp, savePath.Text);
}
The issue arises when i use URL of type:
http://www.dailymotion.com/video/x1coxfe_aryan-khan-tera-pyar-official-music-video-hd_music
which didn't have any suffix i.e. mp3,mp4 etc.
Here it downloads an icon of zero data in the winkle of eye as compared to url having *.mp3/4 etc
Any suggestions please
You should check the Content-Type header not the URL to know the type of file. You can read the content-type like this
string type = client.ResponseHeaders["content-type"];
I have the following code snippet to post on facebook wall. But when I post hyperlink, appears plain text.
public static bool WriteOnFace(string message, string accessToken)
{
string url= "";
WebClient wc = new WebClient();
url= "https://graph.facebook.com/feed?access_token=" + accessToken + "&message=" + message + "&method=post";
wc.DownloadString(url);
}
I'm not using facebook C# sdk. How to Post Hyperlink?
Try using Facebook C# sdk and instantiating a FacebookClient with your access token and then calling the postasync method on it with a link parameter. Something along these lines should work:
FacebookClient client = new FacebookClient('use your access token');
var args = new Dictionary<string, object>();
args["link"] = "[your link URL]";
client.PostAsync("friend's id/feed",args);
Hope this helps!