c# post photo on facebook without using c# sdk - facebook

please provide me a simple piece of code in c# to post photo on facebook without using the very famous facebook sdk for c#, as per my knowledge there are two methods of posting photos,
METHOD 1:
The fb documentation below shows a method to post image with the url provided,
https://developers.facebook.com/blog/post/526/?ref=nf
of course I tried, it does not seem to accept my image url, when I tried debugging here on facebook API explorer using the post method and entered the parameters as below,
SomeAlbumID/photos?=access_token=MyTOKEN&url=http%3a%2f%2fcutree.com%2fcutreefbapp%2fimg1.bmp&message=Family+Tree
It returns an exception saying
{
"error": {
"message": "http\u00253a\u00252f\u00252fcutree.com\u00252fcutreefbapp\u00252fimg1.bmp is an internal url, but this is an external request.",
"type": "CurlUrlInvalidException"
}
}
"internal url, but this is an external request." I am not sure what this means as I am using the same domain as registered on my fbapp, and also giving the request from the server itself.
I have read some where that fb accepts images from only a few servers, can anyone help me out.
METHOD 2:
This is a method where image data in bytes are atttached with the Post body as fb says "To publish a photo, issue a POST request with the photo file attachment as multipart/form-data."
However everyone does that using the fb sdk for c#, can anyone provide simple http post method for this issue.
I have tried streaming image data using a method below
public MyFacebookClass FBPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create("https://graph.facebook.com/" + URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = BmpToBytes_Serialization(new Bitmap("C:\\Users\\atul\\cutreefbapp\\DefaultThumb.bmp"));
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp = req.GetResponse();
if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<MyFacebookClass>(sr.ReadToEnd().Trim());
}

Posting photos by giving a parameter url definitively works. If it doesn’t for you, then you are doing something wrong.
(I just tried it with the URL of your picture on the Graph API Explorer, and it work as I expected it.)
when I tried debugging here on facebook API explorer using the post method and entered the parameters as below,
SomeAlbumID/photos?=access_token=MyTOKEN&url=http%3a%2f%2fcutree.com%2fcutreefbapp%2fimg1.bmp&message=Family+Tree
If that’s the actual address you tried to post to, then the = between photos? and access_token is clearly wrong.

The problem you have is your code isn't correct. In order to post a photo to Facebook you'll need to use a multi-part form data post. I haven't used the C# SDK, but I'm sure it builds a multi-part form post internally before submitting the image.
You will have to do something similar to what is posted here. I was about to post my code that does this exactly for Facebook from my app, but it is a bit long.

Related

AS3: Post to Facebook Wall - Error #2032

I am currently developing an app with which visitors of an event can take pictures using a webcam and upload them to Facebook using an AS3-application. I know I can connect to Facebook, because I can log the user out using the API and I can get all the information. The problem is that I can't post to their wall for some reason. I keep getting the following error:
error #2032: stream error. url: https://graph.facebook.com/********/feed
I use the following code to post to Facebook:
private function postFB(e:Event=null):void {
var _params:Object = new Object();
_params.uid = Facebook.getAuthResponse().uid;
_params.access_token = Facebook.getAuthResponse().accessToken;
_params.message = "I was at the Thanksgiving Day Event.";
//_params.picture = _bitmap;
Facebook.api("/me/feed", postComplete, _params, "POST");
}
As I've said before, I know I am connected to facebook because if I change "POST" to "GET" in my api-call, I get all the information of my account. I have the correct permissions as far as I know (read_stream, publish_stream, user_photos). I use GraphAPI_Web_1_8_1.swc as an api.
The documentation on the entire api is very poor, so I am trying to figure out the problem. It's been a few years since I've tried any of this, so my code has probably aged too far by now. So, any ideas what I'm doing wrong?
publish_stream is deprecated (since years?), you need to use publish_actions.
If that does not work, make sure the Access Token includes all the permissions, you can test this in the Debugger: https://developers.facebook.com/tools/debug/
Side note: AS3 is not getting used very often anymore, the last version of the the AS3 SDK is from 2011. It may be a good idea to switch to the JavaScript SDK.

Facebook sdk Unity open graph action does not display

So, I am trying to implement the facebook open graph posts in our game for highscores, but it doesn't seem to post anything. When I do this:
Dictionary<string, string> data = new Dictionary<string,string>() { {"highscore", "http://samples.ogp.me/111111111111111"}};
FB.API("me/namespace:get_a_new", Facebook.HttpMethod.POST, HandleOpenGraphCallback, data);
When I log the FBResult.text in the HandleOpenGraphCallback callback, I get a valid json response looking like this: {"id":"422166374597399"}. But the problem is that I see nothing on the test account that sent that request. The request obviously kind of worked since I receive an id in my callback function, but I see no post. Do I need to put more information in my dictionary in order to even see the post in the my test account timeline? I also put the "publish_action" permission in my login to be sure.
Thank you.

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

facebook api in blackberry

Hello friends I am using blackberry facebook sdk but that is not working properly. When I use
their skd that is going right but when I create other file and call api them I have face the problem. Please help me. thanks.
I was face same problem when i was tried to use one feature of local image posting on friends wall,but i resolved it using :
Download graph api from http://sourceforge.net/projects/facebook-bb-sdk/. After that i added two thinks.
one was when i wont to post a photo to your friends wall ,you had to put one more key-value in the JSONObject(Request) - that was requestObject.put("target_id",getid()) in publisePhoto method facebookuser.java & facebook.java
Second was, i had to change JSONObject responseObject = fb.write(getId() + "/photos", requestObject, pPhoto.getMIMEType(), imageData, true);
to
JSONObject responseObject = fb.write(getId() + "/photos?access_token="+Facebook.token, requestObject, pPhoto.getMIMEType(), imageData, true);in FacebookUser.java & Facebook.java
where token is Static string from Facebook.java and store the value of access_token (you have to add it)
I hope that will be helpful to you(Little bit).

Titanium.Facebook getting graph api access token

I'm developing an iPhone app with Appcelerator Titanium SDK 1.6.2
I am upload an photo to a users facebook album with the Titanium Facebook module, graph api.
The upload goes just fine and returns the items unique ID.
When I try to parse the JSON from the unique id I'm told i need to pass an access token, which makes sense.
How do I get the access token to be passed to the graph request url?
When I do a XHR GET request while passing Ti.Facebook.accessToken I get the following error
URL: https://graph.facebook.com/10150527948301195?access_token=t4CqzHallahfy4d7RnERrJb4ffOkQfJvrYrGEBoZ4so.epdiI6IjJGR2ZFY1ZTMHh6RlR6ZmNIcVctMHcifQ.NBRMth0vb7pXKcd8lHNz9aremoyNpvrbhz2P3zkgWJU4eHdfewOp1WruBNZS_lSDy0XM0Xu0ACry8aEmSckGJVQJxEioykrNZhT7S9mJG2OKWqMdk6ucg5IMhXMfndF9sdKwWrWb7uPKI57LzIOf5lvA
{
error = {
message = "Unsupported post request.";
type = GraphMethodException;
};
}
And if I don't pass Ti.Facebook.accessToken I'm asked for it.
I'm bound to be missing something, any help would be greatly appreciated.
see this link http://developer.appcelerator.com/blog/2011/02/facebook-module-changes-in-titanium-mobile-1-6-0.html
I think you should be using Titanium.Facebook.requestWithGraphPath(...)