How to get attachement image from facebook messenger webhook - facebook

Facebook messenger webhook recieves attached image only with url which is getting expired in some time. How to obtain more information from facebook api to generate new url?

There is not an api to get information about message attachments currently.
I am not sure if/when the image will be deleted, as there is no mention of this in the docs. If you want to guarantee permanent access to the image, you should store it somewhere like s3.
An example of this using knox:
http.get('http://google.com/doodle.png', function(res){
var headers = {
'Content-Length': res.headers['content-length']
, 'Content-Type': res.headers['content-type']
};
client.putStream(res, '/doodle.png', headers, function(err, res){
// Logic
});
});

Related

Microsoft Graph ListMessages API not providing the emails

I am currently using Microsoft Graph API v1 to retrieve the list of messages present in a user's inbox and I have all the necessary scopes listed in order to read and write messages on behalf of the user, the scopes are
openid,
email
profile
offline_access
https://graph.microsoft.com/mail.read
https://graph.microsoft.com/mail.readwrite
https://graph.microsoft.com/mail.send
https://graph.microsoft.com/user.read
When I make an api call to fetch all the messages from the mailFolder INBOX through the api listMessages API, I am getting the messages, but the api in itself doesn't return some mails even though I can see them in my Inbox folder in Outlook UI.
Are there any other settings or parameter that I need to enable in order to get all the mails?
The receiver from whom I received the mail is in my SafeSender List and not in any Blocked List
Any suggestions or answer would be helpful
An example code of what I am doing is as follows
function getUserMessages() {
const baseUrl = "https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages";
return axios({
method: 'GET',
url: baseUrl,
headers:{
"Authorization": "Bearer <access_token>"
}
}).then((result) => result.data);
}
// Here in the messages I get, I don't see some of the mails which are
// present in the inbox Folder
const messages = getUserMessages();
Graph pages the returned messages. You can specify $top and $skip query parameters (in addition to $orderBy). It also returns #odata.nextLink value in JSON response that you can use to request the next page.

deleting facebook requests

The facebook docs here say "it is the Developers' responsibility to delete a Request once it has been accepted". As far as I understand, when someone sends a request to multiple users on facebook like this:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'test message'
}, requestCallback);
}
only one request_id is returned via requestCallback() function.
Then, if I delete the request when someone accepts it, how would other users accept the deleted request?
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to delete the corresponding requests like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Check out the Request ID Format section of the FB request overview page.
The actual graph path for a request actually sent to specific user is "request-id"_"recipient-user-id".
you can access to facebook on mobile mode (m.faceook.com)
1-access the invitation panel
2-display all the invitations
3-open console mode in chrome
4-activate jquery by cpying and pasting all the jquery.min code into console
and excecute this script :
$("._54k8._56bs._56bt").trigger("click");
that will cancel or the invitation sent

facebook oauth, no picture with basic permissions

I'm using oauth to log facebook users in to my app. I'm testing with my FB account and with the basic permissions scope. Facebook docs say that I should be able to get 'picture' with basic permissions, but my account has no 'picture' property when I access it with the API. First name, last name, etc. are there though.
Is this because my account is not publicly viewable? Why might this happen? I definitely have a profile picture attached.
Here's my fb link: http://www.facebook.com/josh.nankin
best way is to keep the basic permissions and fire the request for the image in a separate step. Ask the graph api in this way:
https://graph.facebook.com/[fb_user_id]?fields=picture.type(small)
larger image:
https://graph.facebook.com/[fb_user_id]?fields=picture.type(large)
You will get a JSON response like:
{
"id": "100001XXXXXXXXX",
"picture": {
"data": {
"url": "http://profile.ak.fbcdn.net/hprofile-XXXX/41524_1000018XXX51507_XXXX3_q.jpg",
"is_silhouette": false
}
}
}
You can derive the profile photo URL directly from the basic standard OAuth info returned from facebook as Josh Nankin noted, BUT with a clarification.
You can still use the user's ID returned to request the photo, for example:
https://graph.facebook.com/914431778578699/picture?type=large
is the same as
https://graph.facebook.com/dark.eye.1/picture?type=large
This way only one request must be made, because you can interpolate the photo URL as you store it in the DB.
So, still not sure why the graph api does not return a picture property when you hit the /me path on the API, but once you have the username from /me, you can get the picture pretty easily at:
https://graph.facebook.com/USERNAME/picture
https://developers.facebook.com/docs/reference/api/user/:
“picture: The URL of the user's profile pic (only returned if you explicitly specify a 'fields=picture' param)”
You haven’t probably overlooked the part marked in bold …?
Actually you don't need to allow public access to get the profile picture since you can get the USER_ID. Though the USER_ID you can navigate to the profile picture easily.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
console.log('Welcome! Fetching your information.... ');
var url = '/me?fields=id,name';
FB.api(url, function(response) {
var linkpp = 'https://graph.facebook.com/' + response.id + '/picture?type=large';
document.getElementById("id_of_link_tag").href = linkpp;
});
});
}
You can change the type in variable linkpp to type=small which returns a low resolution image.
var linkpp = 'https://graph.facebook.com/' + response.id + '/picture?type=small';

delete facebook requests via graph api

I am getting latest apprequest like this:
FB.api('/me/apprequests', function(response){
if (response.data[0]) {
// code here
};
How to delete apprequest using the same graph api method , I know this is possible with request containing access_token ... but in this case I am caching html and didn't know how
Thanks
Please use the following code (PHP):
file_get_contents('https://graph.facebook.com/'.$rid.'?access_token='.$token.'&method=DELETE') == "true";
// $rid: Request Id
// $token: Access Token
// The response is generally just the text "true"

Facebook tagging user on a photo in a Page Gallery via SDK and Graph is possible?

I'm trying to tag a user (having its userid), with a Graph request made to a picture just uploaded to a Page Gallery.
Permissions I use in the app are:
#"read_stream", #"offline_access", #"publish_stream", #"manage_pages",#"photo_upload",#"user_photos" and with a access_token to the session got from page_it?fields=access_token item (that works for picture upload in gallery).
And I use them to upload the photo to a Gallery on a Fan Page successfully.
When I try to tag the user with a graph request in the form:
POST to picture_id/tags with param: "to"->userid
I get only facebookErrDomain error 10000 as if permissions are not right.
From API Documentation seems that only user_photos and publish_stream are required and no mention to page-galleries photo is made.
I'm quite clueless about this issue.
It's possible. You need to collect the page's specific token by placing a call to /me/accounts. And then tag the photo using page's access token. Once you get that, you can tag the photo using it's Graph Object Id and user id whom you are tagging.
if (accessToken) {
var data = {
"access_token": accessToken,
to:userId,
x:x,
y:y
}
FB.api("/" + photoId+"/tags/"+userId , 'post', data, function(response) {
//here is the response
});
}
Hope it helps. The key is the access token that is specific to that page :)