get a specific link of downloaded google search site - httpclient

I want to do the following in C#:
load website in background (google search site)
look into the sourcecode of this site and get a specific link
I tried this before:
Use the WebClient Class to download the String of the website
WebClient client = new WebClient();
string reply = client.DownloadString(url);
client.DownloadFile(gesamter_String, #"C:\neu\localfile.html");
Console.WriteLine(reply);
Use the HTTPClient Class to download the String of the website
string url = hyperlink;
HttpClient client = new HttpClient();
using (HttpResponseMessage response = client.GetAsync(url).Result)
{
using (HttpContent content = response.Content)
{
string result =content.ReadAsStringAsync().Result;
Console.WriteLine(result);
}
}
But the downloaded or displayed sourcecode is very small and doesn't contain the specific link.
However my links works. I have opened the link in foreground with this: System.Diagnostics.Process.Start(url);. This foreground opened site contains the full sourcecode.
Thanks a lot.

Related

Redirect URL from local filesystem to internet with browser WebExtension

To summarize the problem, I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet (i.e. clicking the link opens the browser and takes you to file:///page instead of http://domain/page).
Getting these files modified to include the full URL is not an option. My question is almost identical to the question I asked a year and a half ago. The difference is that I need to port my existing extension (made with the Firefox SDK) to the new WebExtensions API for Firefox (same as Chrome extensions).
There are methods available for redirection, such as
browser.webRequest.onBeforeRequest.addListener(
redirect,
{urls:[pattern]},
["blocking"]
);
but that only accepts http:// and https:// URL patterns.
I am currently trying to use the following code:
var id;
browser.tabs.onCreated.addListener( details => id = details.id )
browser.tabs.onUpdated.addListener( (tabId, changeInfo, tab) => {
var url = changeInfo.url;
if (tabId == id && url.includes("file:///")) {
url = url.replace("file:///page", http://domain/page");
browser.tabs.update(
id,
{ url: url }
);
}
});
Unfortunately, I have the same fundamental issue as with my original problem, resulting in the onUpdated listener not firing (or if it does fire, it's not because of a URL change). But regardless of the listener used (e.g. onCreated, onActivated, etc.), I get about:blank for the URL.
I have tried injecting code to change the value of the address bar, but that doesn't seem to work either:
browser.tabs.executeScript( {
code: "window.location.href = window.location.href.replace('file:///', 'http://domain/')"
});
Thanks for any help!
redirectUrl : chrome.extension.getURL("hello.html")
Worked for me

j2me facebook graph api - posting image on a user wall

I'm trying to post image from device on user's wall. I have found: http://codenameone.blogspot.com/2011/09/lwuit-and-facebook-api-by-chen-fishbein_18.html, but it doesn't support post image, so I wrote a simple method like this:
public void postOnWallWithPhoto(String userId, String message, byte[] img) throws IOException {
checkAuthentication();
FacebookRESTService con = new FacebookRESTService(token, userId, FEED, true);
con.setContentType("image/jpeg");
con.addArgument("message", message);
con.addArgument("type", "photo");
con.addArgument("picture", img);
if (slider != null) {
SliderBridge.bindProgress(con, slider);
}
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) elementAt(i));
}
current = con;
NetworkManager.getInstance().addToQueueAndWait(con);
}
This method is called in this way:
FileConnection fc = (FileConnection) Connector.open(path);
InputStream is = fc.openInputStream();
byte[] b = new byte[(int) fc.fileSize()];
is.read(b);
FaceBookAccess.getInstance().postOnWallWithPhoto(me.getId(), "test2", b);
After I send request, on a wall appears only text (in this example test2). In place where should be an image, there is a message: "invalid invalid".
Does anyone have idea, what I'm doing wrong? Or can someone share with me a code that will help me in posting images on a facebook wall?
The old LWUIT facebook login no longer works properly due to changes made by facebook to their login process.
This only works with Codename One which also supports image posting in its current facebook demo.
As we all know J2me does not provide with any in api for facebook support but there is a way we can still post images on facebook wall and i have done that.
Below i am sharing a breif procedure of how we can post images to facebook wall using j2me.
Get the ACCESS TOKEN from from facebook: You can do it using PHP or any third party api for getting it done(in my case i used app42(shephertz) cloud services)
Once you have the ACCESS TOKEN use that access Token to get the facebook userid on which you want to post the image.
And once you have the userId only thing left is to upload the image to facebook using 'MultiPart Request'. Below are some important statements from my code(I am not sharing my whole code because i have used third party api(app42) to get the access token and user id).
Url for facebook:
String url = "https://graph.facebook.com/" + user_id + "/photos?access_token=" + accessToken;
image stored in byte array : byte fileBytes[];
HashTable used in multipart request(you can copy it as it is):
Hashtable params = new Hashtable();
params.put("custom_param", "param1");
params.put("custom_param2", "param2");
A class that is sending my multipart request
HttpMultipartRequest req = new HttpMultipartRequest(url, params, "upload_field", "original_filename.png", "image/png", fileBytes);
you can use the following link to refer Multipart request
http://www.developer.nokia.com/Community/Wiki/HTTP_Post_multipart_file_upload_in_Java_ME
And once you are done with it i hope u might have successfully posted an image on facebook wall.
Happy Coding..

WP7 Facebook integration using C# SDK

I want my game player to able to post game score to his facebook wall from WP7 game. I have gone through following tutorials
1> Tutorial: Logging Into Facebook with Windows Phone 7 (Silverlight) (source code is downloaded from their website.)
PROBLEM: After running sample project, i can login to facebook, but can't figure out how to post the message.
2> I have download sample project from github.
PROBLEM: When i open the project for WP7, a window pop up saying "Solution folder are not supported in this version of application. solution folder '.nudget' will be displayed as unavailable."
I have tried downloading nuget updates as suggested by Prabir's Blog.
3> With this tutorial, i am able to login to facebook.
PROBLEM: unable to post any message. it display inside emulator "The remote server returned an error:NotFound".
please let me know if you find this question inappropriate or lack of research, i will romove question immediately.
I am novice to both WP7 and C#. Please help me to correct above problems.
Thanks in advance
EDIT : Finally got 3rd one working by making small changes in PGLogin.xaml.cs, just change "PRE" to "pre" in "wbLogin_LoadCompleted" method. but still not much satisfy. because its work and sometime don't. it's not stable. and don't know how to logout. any suggestion?
Another user had this exact issue, it was resolved using the following code:
var args = new Dictionary<string, object>();
args["name"] = "Check this out";
args["link"] = "www.xyz.com";
args["caption"] = "";
args["description"] = "description";
args["picture"] = "";
args["message"] = "Check this out";
args["actions"] = "";
FacebookAsyncCallback callBack = new FacebookAsyncCallback(this.postResult);
fbApp.PostAsync("me/feed", args, callBack);
private void postResult(FacebookAsyncResult asyncResult)
{
System.Diagnostics.Debug.WriteLine(asyncResult);
}
Post to Facebook wall using WP7 and Facebook.dll
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "Divum Photo Browser";
shareLinkTask.LinkUri = new Uri(list_photos.ElementAt(index_).imageUrl, UriKind.Absolute);
shareLinkTask.Show();

Post image link with Facebook C# SDK problem

I try to post my image link to Facebook fan page using Facebook C# SDK.
var client = new FacebookClient(this._accessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://photos-f.ak.fbcdn.net/hphotos-ak-snc6/260418_185563101499189_124421460946687_425466_2105002_t.jpg";
parameters.picture = "http://photos-f.ak.fbcdn.net/hphotos-ak-snc6/260418_185563101499189_124421460946687_425466_2105002_t.jpg";
parameters.name = "My Picture";
parameters.caption = "My Picture Caption";
parameters.description = "";
dynamic result = client.Post("{Fan page ID}/feed", parameters);
An error occur like below.
(OAuthException) (#100) FBCDN image is not allowed in stream:
http://photos-f.ak.fbcdn.net/hphotos-ak-snc6/260418_185563101499189_124421460946687_425466_2105002_t.jpg
But if i set "picture" parameter to empty string it work perfectly.
How could i fix this problem?
Facebook doesn't allow you to re-post or hot-link images that are hosted on their CDN. They added this policy and error message back in June 2010. You will need to upload this photo to some kind of non-Facebook server or photo sharing site and then use that url.

How can I use the Facebook C# SDK to post on Facebook Pages

I have already requested and gained access to 'manage_pages' and 'publish_stream' permissions from a user. How can I use the c# SDK to get permission to post to one of that user's Business Pages wall (They must select one if they Admin multiple Pages, right?). Once I have that access, what is the best method to use the SDK to post to the Business Page wall?
On a related note, can the C# SDK run under ASP.NET 3.5 effectively? Rackspace Cloud Sites is not allowing .NET 4.0 on production servers yet, so I need to see code examples that don't use the 'dynamic' or 'ExpandoObject' keywords.
Thanks!
following is the code if it helps you
FacebookApp fbApp = new FacebookApp();
FacebookApp app = new FacebookApp(fbApp.Session.AccessToken);
var args = new Dictionary<string, object>();
args["message"] = "abc";
args["caption"] = "This is caption!";
args["description"] = "This is description!";
args["name"] = "This is name!";
args["picture"] = "[your image URL]";
args["link"] = "[your link URL]";
app.Api("/me/feed", args, HttpMethod.Post);
You need to replace /me in app.Api's arguments to the specific id of page.
I'm not sure if its the right way, but it works for wall post of a user :-)
Here's how with c# SDK 5.1.1
FacebookClient fbClient = new FacebookClient(accessToken);
var args = new Dictionary<string, object>();
args["message"] = "Testing 123";
fbClient.Post("/me/feed", args);
args["picture"] = "[your image URL]";
args["link"] = "[your link URL]";
The image url and link won't work if you give a localhost address.You can try by giving url of an image in a remote server.