Post image link with Facebook C# SDK problem - facebook

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.

Related

Facebook SDK Login URL Exposing the Client Secret?

I'm currently building a website where I'll offer the users a link to share a photo on Facebook, whereby the application would:
Provide the user with a link to request permissions from Facebook
Redirect back to the website with the access code from the user's acceptance of the permissions
Server-side post the photo to the user's photos
To generate the link for the first step, I'm doing this:
var fb = new FacebookClient();
var options = new
{
client_id = "MY_APP_ID",
client_secret = "MY_APP_SECRET",
redirect_uri = string.Format("http://localhost:51182/Home/FacebookShare?path={0}", Server.UrlEncode(path)),
response_type = "code",
scope = "publish_stream"
};
var loginUrl = fb.GetLoginUrl(options);
Then this loginUrl value is added to my MVC ViewModel and used in a link in the View.
However, I've noticed that the loginUrl contains the client_secret value in clear text. Isn't this a bad thing? Shouldn't users not be able to see the client_secret? Did I go about this the wrong way?
The fb.GetLoginUrl method is rather simple, in that it just adds anything you give it inside the options object as parameters to the URL created.
So take
client_secret = "MY_APP_SECRET",
out of your options object, and it should not show up in the login URL any more.

Post on Facebook page wall or timeline

As FaceBook launched a new concept of pages, I created a page, but I am not able to find any C# SDK for posting on that page's timeline from code.
First you need C# SDK
you can download from here
http://csharpsdk.org/
may be you need manage_page permission to get a page access token
you can get a page access token using this Graph Request http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts
after getting page access token you can post a on page wall using this code
var fb = new Facebook.FacebookClient(PageAccessToken);
var postArgs = new Dictionary<string, string>();
postArgs["link"] = "http://www.foo.com";
postArgs["name"] = "Click Here To View";
postArgs["message"] = Message;
fb.Post("[pageid]/feed/", postArgs);

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..

mobile version of Facebook app going into redirect loop

I have developed a Facebook app using the C# SDK and it is working fine. Now I want to also enable it on mobiles, so I tried to set the "mobile url" to the same one as my canvas url (which is a cloudapp.net address). However, when I try to access it from a mobile, it seems to go into a redirect loop involving my canvas url, the apps.facebook url and the m.facebook/apps url. Sometimes it goes out of the loop and I get the facebook error message saying : "the mobile version of the app is unavailable because it is misconfigured. It appears to be caught in a redirect loop."
I think it may have to do with the fact that the facebooksettings in the webconfig file specify that my cloudapp page should redirect to the apps.facebook.com page, which then redirects to the mobile url and so on. Can someone tell me how to solve this problem - I just want my mobile url to be the same as my canvas url.
Thanks.
If the request is from mobile add extra logic
For v6,
var fb = new FacebookClient();
var desktopLoginUrl = fb.GetLoginUrl(new { .... });
var mobileLoginUrl = fb.GetLoginUrl(new { ...., mobile = true });
For v5,
var urlBuilder = new UrlBuilder(oauthClient.GetLoginUrl(...));
urlBuilder.Host = "m.facebook.com";
var loginUrl = urlBuilder.Uri;

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.