This is my sample code where I get the message from the user. It's text only, so how can I get if I receive an image from the user? I'm using PHP from my bot.
$message = $input['entry'][0]['messaging'][0]['message']['text'];
get the value of attach file using php:
$message = $input['entry'][0]['messaging'][0]['message']['attachments'];
to post the result => $message[0]['payload']['url'].
You will have the image url at:
entry[0].messaging[0].message.attachments[0].payload.url
To check if you have recieved a text or an image :
if(entry[0].messaging[i].message.text)
//text
else
// image
Related
I am sending apprequest to send "Gift" to friends.
Code which i am using to send gift is as below :
FB.AppRequest (Send_Gift_Message, OGActionType.SEND, GIFT_10_COINS, toFriends, null, "Send Gift", delegate(IAppRequestResult result) {
});
This is sending gift request perfectly but i just want to change message which is shown while sending gift.
I am attaching image which shows message :
I want to change "sent you a coin:". I want to use "sent you coins:".
Is it possible to change ?
If it is possible then plaese guide me steps.
Thanks.
I am using the grails facebook-sdk plugin to connect and post to facebook.
To publish a message to a user's wall I use:
def publishMessageResponse = facebookClient.publish("me/feed", [message:"RestFB test"])
This works fine, but I want to post an image to a specific album of the user. The documentation says that it should work with:
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], "/cat.png")
But I alway get a "File not found" error. The image I have is stored in a data base and can be retrieved by getting the url to the image.
Knowing the url of the image, how can I post this image to a specific user photo album? How can I create a new Album?
I haven't used the facebook-sdk but I would assume that the issue is that it can't find the file '/cat.png' relative to the location of you're project. You'll need to provide valid and accessible file path.
You could confirm this by doing something like this before publishFile...
assert new File("/cat.png").exists(), "File does not exist!"
UPDATE:
Here is an example of converting a url to a file. This may not be the ideal solution if there are other options besides using an actual file.
def someUrl = "http://www.google.com/images/logo.gif";
def file = File.createTempFile("facebookUpload",".temp").withOutputStream { out ->
out << new URL(someUrl).openStream()
}
file.deleteOnExit();
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], file)
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..
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.
Hi i'm new developer of fb apps and i want to know how can i send a message to the wall of my friends using the new facebook.php class http://github.com/facebook/php-sdk
I do it this
$result = $facebook->api('/me/feed/',
'post',
array($ids,'message' => 'Playing around with FB Graph..')
);
This code work for the firts time i can login in the application after i try to enter again and the application sending and error The message if duplicated.
How can i fixed or what if the best way to do?
Thanks.
The error you are having is because facebook wont let you send the same message to the same user multiple times hence the error duplicate message. Change the text of the message and the message will work.