Facebook Graph API call only sends to first person specified - facebook-graph-api

I have the following Facebook Graph API call:
FB.ui({
method: "send",
to: '123123,456456',
name: 'People Argue Just to Win',
link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html'
}, function(response) {
// some stuff
});
Whenever it's invoked, my message's only recipient is the user with id 123123. If I switch the two numbers, the 456456 is the sole recipient.
As far as I can tell, I'm using the API exactly like I'm supposed to, so what could I be doing wrong?

It looks like it's not possible with the send method to specify multiple recipients: http://bugs.developers.facebook.net/show_bug.cgi?id=18806
It does look like it can be done with the apprequests method, though:
FB.ui({
method: 'apprequests',
message: 'My message',
data: {},
title: "My Title",
to: [123123, 456456]
});
For my purposes, that's close enough.

Related

I am using htmx javascript API how do I get the response from server

My code block looks like this, basically when a modal is triggered I send a GET request and retrieve the response, it does send the request alright, but I am unable to see (or to put it better) to get the response from the server via .then() from htmx. I am using the example from there documentation.
htmx.ajax('GET',
'/user-related-comment/',
{ swap: 'none', values: { userId: userId } }
).then(data => {
console.log(data)
})
data is undefined when logged to browser console.
For anyone that needs to do this, an option will be to listen to 'htmx:afterOnLoad' event example.
htmx.ajax('GET', '/example', '#myDiv').then(() => {
document.body.addEventListener('htmx:afterOnLoad', event=>{
console.log(event)
// access response at event.detail.xhr.response
// convert to JavaScript object by JSON.parse(event.detail.xhr.response)
})
});
For some reason on first click, does nothing.

Slack Modal and AWS Lambda: Returning response_action after wrong user input throws an error in modal

I´m currently building an Slack app with a modal. I´m using a serverless AWS Stack containing a Lambda function that handles the user interactions. Those interactions are verified in that Lambda.
If the user input is correct, the modal is closed successfully (Lambda returns a 200 response). However, if I return the following as the body when user input is wrong and user submits the modal (as per Slack´s documentation):
{
"response_action" : "errors",
"errors": {
"startDate": "Start date is incorrect.",
},
}
The full response I'm returning at the end of the Lambda function is:
response = {
statusCode: 200,
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
response_action : "errors",
errors: {
"endDate": "Start date is incorrect.",
}
})
};
I receive the error in the next screenshot:
Am I missing something? Thanks a lot.
So I found the problem and here´s the solution in my case (might be helpful to you reader):
The right block type
The modal I built is made of interactive components, like a date picker. These components are blocks of type "section". For better comprehension, they look like this:
However, it seems that´s not compatible with the the feature to display input errors. For that, you have to choose blocks of type "input". Again, for understanding, they look like this:
And that type of block is compatible with displaying error messages as per Slack documentation.
The response from AWS Lambda
When you validate a user input, in the AWS Lambda function, Slack expects you to return the following structure in the response if you want to warn about an error:
{ "response_action": "errors", "errors": { "ticket-due-date": "You may not select a due date in the past" } }
However, it looks like you need to indicate the time of content by adding a header defining content is of JSON type without a statusCode. In my case, response that works is:
response = {
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
response_action : "errors",
errors: {
"test": "That date is invalid. Please, select a future date.",
}
})
And that way, the custom error message appears:

Differences between Share Dialog, Feed Dialog and share_open_graph

I have a project where I need users to share content via app.
After that I will need to track how many shares were made per day.
Now I can share a link using three different functions as follow:
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/',
hashtag: '#myhash',
}, function(response){console.log(response)});
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object:'https://developers.facebook.com/docs/javascript/examples',
})
}, function(response){
// Debug response (optional)
console.log(response);
});
FB.ui({
method: 'feed',
link: 'https://developers.facebook.com/docs/',
ref: 'ref1, ref2'
}, function(response){console.log(response)});
The only differences I can see is that using share I can add hashtags and feed dialog I can add refs. Visually they all look the same on the feed...
Will any of these be more benefitial than the others assuming later I want to search and analyse the shared content? (for example, different hashtags and / or different sources like mobile / web)?

facebook unsupported post request

I have logged in a user to my app from FB.login now I want to post to the user timeline on the behalf of user. I want to upload a video to the user timeline. I am doing something like:
FB.api(
`/${user_id}/videos`,
"POST",
{
"file_url": video,
"description": description,
"thumb": video_thumbnail,
"title": title,
},
function (response) {
console.log("fb response")
console.log(response)
if (response && !response.error) {
/* handle the result */
console.log("video upload response")
console.log(response)
}
}, {scope: ['user_videos', 'user_actions.video']});
When I do this it is giving me error saying code: 100
fbtrace_id: "F1BDJWtcTXl"
message: "Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
type: "GraphMethodException"
Why I am getting this error ??
Help is appriciated ..
Thank you
Use /me/videos instead of /${user_id}/videos and use single (or double) quotes instead of "`".
Also, you need publish_actions only, and you need to use the scope parameter with FB.login. FB.api is just an API call.
Here´s an example for the login: http://www.devils-heaven.com/facebook-javascript-sdk-login/
And here´s the link to the docs for uploading videos: https://developers.facebook.com/docs/graph-api/reference/user/videos/#Creating
Someone suggested that the App may be in sandbox/dev mode, no sure why this should be a problem but here´s the thread: How to fix "Unsupported post request" when posting to FB fan page?

how to use facebook API getting friend's list in javascript

I am not familiar with using Facebook Javascript SDK.
My story is when I access to the website It displays all my friends(pic and name) on a webpage.
I registered Facebook API and App ID
I put website URL as http://localhost:81/ because I am testing my own local machine.
Do you have any good example website or good examples?
Please share with me
Thank you.
First your app should use required permissions like,
user_birthday, friends_birthday, user_location , friends_location...
( for more permissions)
Get info about current user:
FB.api('/me', function(response) {
// Stuff here
});
Get info about current user's friends:
FB.api('/me/friends', function(response) {
// Stuff here
});
you will get the response like,
{data: [{id: "FRIEND1_ID", name: "FRIEND1_NAME"}, {id: "FRIEND2_ID", name: "FRIEND2_NAME"}]....}
If you want get some more properties of your friends, use FIELDS parameter, like
FB.api('/me/friends', {fields: 'name,id,location,birthday'}, function(response) {
// Stuff here
});
If want to get individual user's friend info:
FB.api('/FRIEND1_ID', function(response) {
// Stuff here
});
Try this Example Site
Direct Access Method:
Log into Facebook under your name. If you need an "Access Token", Click on the Extended Permissions and click the "read_friendlist" check box to get your Access Token and then
submit your query. You may need to "Allow" access, so just follow the prompts given.
Voila! You now have the usernames for everyone on your Friends List. The "username" parameter in the query will give you the contact email "message to that person" and you append #facebook.com and send them a message. Very simple.
http://developers.facebook.com/tools/explorer?fql=SELECT%20username%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29%20ORDER%20BY%20name
-SAB