I am attempting to post on a group page using the FB JS API, basically the user selects the group they want to post onto, and it posts it to the wall.
i am doing:
FB.ui(
{
method: 'stream.publish',
from: myId,
to: groupID,
attachment: {
name: 'Post to a group Test,
href: 'http://www.test.com'
}
});
But when i try it, it says:
An invalid target was specified:
<(groupid)>. The target must be a
page, event, or user that the actor
can post on the wall of.
Thou, i know i can post on the group page, so i dont know why it says that.
And i am not talking about fan pages, i can post on them ok setting the from and to as the same thing (posting as an admin).
Is this possible? or am i just doing it wrong?..
Thanks,
Andrew
It seems that both stream.publish and feed methods are not supported for groups object so your best solution is to use (for example) the jQuery UI Dialog component with the fields you need to post to the group as inputs and on the submission use the FB.api method:
FB.api("/group_id/feed", 'post', { name: nameVar, link: linkVar }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
I'm not experienced, with the facebook API, but what is the value of the groupID variable? is it "(groupid)"?
If not, then it is a really unclear error message - and I wonder how the API knows that you tried to post on a group.
If so, then there you have it ;-) You should fill in a group id.
According to the documentations, Facebook groups are not mentioned in the list of possible targets to publish to. I filed a bug to hopefully get Facebook to address this:
http://developers.facebook.com/bugs/158247050931954
Related
I can't seem to find a solution when I get a push notification and click on it redirects me to a screen, chat, etc. link to push notification.
I would also like to add a square image to the side and could not find an answer.
The push notifications are sent from a NodeJS server I looked at the docs and search the internet and I did not find anything of interest.
https://docs.expo.dev/versions/latest/sdk/notifications/#managing-notification-categories-interactive-notifications
https://github.com/expo/expo-server-sdk-node
Thank you in advance for your answers ❤️
I'm not quite sure about the square image, but in order to handle redirects you can look at this documentation from expo: https://docs.expo.dev/push-notifications/receiving-notifications/.
You can then pass the data you need for your redirect (i.e. notification_type, relevant id etc) via the data property on your message (this will need to be done wherever the message is created, which from your question is from the node api):
messages.push({
to: pushToken,
body: 'This is a test notification',
data: { notification_type: 'something', id: 'something_else' },
});
It is then up to you to decide how to handle that message based on the extra data you have provided.
For example, taking the code provided in the link above as an example, you could have a handle function as follows:
_handleNotification = response => {
const data = response.notification.request.content;
if (data.type === "new_message") {
// navigate to MessageScreen with data.id as param
} else {
// do something else based on the type or...
}
};
I am setting up a website. I want users to invite Facebook friends to look at the page the users can make on my website. So i'm trying to get it done. But i think the FB Api is not set up to do what i want to do. I think it is to prevent from spamming, but i really like to know if it can be done or not.
This is what i have so far. Users can login with FB and i present a decent list of FB friends.
Each friend has a checkbox. When a user submits the form, i collect all the checked friends id's:
var sendUIDs = '';
var mfsForm = document.getElementById('mfsForm');
for (var i = 0; i < mfsForm.friends.length; i++) {
if (mfsForm.friends[i].checked) {
sendUIDs += mfsForm.friends[i].value + ',';
}
}
While i was trying, i came up with this "sollution" for sending all the friends the same invite:
FB.ui({
method: 'apprequests',
to: sendUIDs,
message: "Hey come on look at my site",
data: "mywebsite.com/userlink"
});
Looking great I thought. Exactly what i wanted... i thought.
Unfortunately this is only used for games? First of all i could not find the invite. It was there, but it seems to disappear. Then i found out it was in the App/Games/Activity tab.
I managed to get the notification in the "notification" tab by adding a Canvas to my FB App. Almost there i thought. Well, not exactly... I want the friends to visit my page by the given data link and not some weird ?number.
So i gave up this path and tried the other way and came up with this:
for (var i = 0; i < mfsForm.friends.length; i++) {
if (mfsForm.friends[i].checked) {
var uid = mfsForm.friends[i].value;
FB.ui({
to : uid,
method: 'send',
name: 'Visit my page',
link: 'mywebsite.com/userlink'
});
}
}
This works more or less, but produces a popup for every friend with an empty message box. Not very friendly and, well... stupid :)
I also tried the former setup, but instead of "apprequests" i used this:
FB.ui({
method: 'send',
to: sendUIDs,
message: "Hey come on look at my site",
data: "mywebsite.com/userlink"
});
where i tried this for the sendUIDs: [1, 2, ...] and just 1, 2, ...
No luck, because FB only processed one name.
I would think there must be a way to get the job done, but for now i am very confused how to proceed. I would think FB could make things a bit more easy?
The Send and Share Dialogs are built for this (sharing a Website URL on a wall or send it to friends in a PM), just let him choose the friends in the popup. That way, you don´t even need to authorize the user, and you can´t get ALL friends anyway (only those who authorized the app too).
About the message parameter: You are not allowed to prefill the message, it has to be 100% user generated. See the Platform Policy: https://developers.facebook.com/policy
2.3 Ensure that all content in the user message parameter is entered by the user. Don’t pre-fill. This includes posts, messages, comments,
and captions.
The FB.ui Dialogs ignore the message parameter anyway.
I have some trouble with the Facebook FB.UI - Feed and Sare dialog.
I need to send the page of the website to a friend, im using the FB.UI Javascript API. According to the facebook documentation they said you have to use the "from and to" parameter. But when i use the "from and to" parameters it doesn't work. When i delete these parameters it works fine, but i cant post to a friends wall for sure.
I've been looking for a while, and have try'd the following steps:
Does the user have enabled the right settings to post on his timeline (check)
Does the user have liked the facebook page (check)
Am i logged in (check)
This is the link to the documentation: Feed and Share Dialogs
This is my code:
PS: I get the alert what is saying: "Post was published" but it doesn't show up on facebook.
function share()
{
FB.ui({
method: 'feed',
name: 'The name',
link: 'The URL',
from: '100001738814056',
to: '100003105898115',
caption: 'An example caption',
}, function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
edit: I've got some more information about my problem, and i guess i found the problem..
If you take a look at this image you'll see a row with: "Feed" and one with "?api_key=". If im taking a look at the URL of feed i guess it misses the get api key, not sure if iam correct
The image link
We'll after a day of searching.. i know the solution.
If you create an app in Facebook, the mode of the app is " in sandbox mode ", when you turn the sandbox mode off you can post to facebook while tagging a friend!
So my problem is solved.
I have created a Story using Open Graph and the object I want to use is called Service, which is really just a Profile but I want the text in the post to say 'service' rather than 'person' (which it does now). I have tried creating a custom object but it seems overly complicated for what I need so I have 2 questions:
Can I create a custom type that simply inherits from Profile that can be created in the same way (using the FB.api javascript method)? I don't want to have to use self-hosted types..
Can I simply re-label person.noun from 'person' to 'service' somehow? I can't see a way to do that..
My code to post the story is:
FB.login(function (response) {
if (response.authResponse) {
var strmessage = 'Some message';
var profileid = 'xxxxxxxxx;
var opts = {
profile: profileid,
message: strmessage,
no_feed_story: false,
'fb:explicitly_shared': true
};
FB.api('https://graph.facebook.com/me/mynamespace:myaction', 'post', opts, function (response) {
if (!response || response.error) {
Result("Your message has not been posted");
}
else {
//Message has been posted
Result("Your message has been posted");
}
});
You're going to have to do the custom object if you want a custom name. And, you're going to have to do it on the FB Developer site and go through the whole approval process and all that. And no, there is no way to do any sort of inherence on this.
FB's Open Graph is pretty simple if you use the built in actions and objects, but as soon as you go down the road of wanting custom names for stuff, you are going to have to go all in with it.
I finally put the time aside to implement a custom action and type. It wasn't the most intuitive process but I got there in the end and my app is now approved and doing exactly what I wanted it to do. I'm actually glad I put myself through this learning process as custom stories have great potential and I'm sure I'll find other applications for them in the future.
I try to post a YouTube video directly into a Facebook Event wall, using the Graph API.
When posting to a FanPage wall I get a desired result (Post with preview picture and the video itself), But when posting to an event wall, I only get the message, without any video and preview picture.
Here's the code:
var eventObj =
{
source:'http://www.youtube.com/v/'+youTubeID,
picture:'http://img.youtube.com/vi/'+youTubeID+'/0.jpg',
message: messageText,
name: eventName,
caption: newDateArray[0] + ' ' + newDateArray[1].substr(0, 5)
};
FB.api('/'+facebookEventID+'/feed', 'post', eventObj, function(response){
//response code...
}
After this code is executed, I get a new post in the Event Wall, with only the messageText being displayed. I've tried sending only the source, but then it returns an error object with message it cant create a post without a message, so I tried sending both source and message and got the same result: only the message was displayed.
UPDATE BASED ON ANSWER:
I've tried using your code and your permissions, and the results are the same:
I get only the text:
Maybe its because I'm posting as a FanPage ?
Do you have any idea how to solve it ?
UPDATE #2 BASED ON ANSWER:
It seems that for some reason an event created from within Facebook has a newer version of the post UI then an event created from an application using the Graph API.
This is from the event created within Facebook:
And this is from the event created with the Graph API:
You can see the second is an older version, and I guess this difference is also causing the problem of uploading YouTube links to events created by the Graph API, As I succeed uploading a YouTube link from the API to an event created by me from within Facebook.
Really? I was able to post a YouTube link to an event using my test app:
function post() {
var eid = 508688182476978; // Event id.
FB.api(
'/' + eid + '/feed',
'post',
{
message: 'Testing SDK',
source: 'http://www.youtube.com/v/kohozJp9dNs',
picture: 'http://img.youtube.com/vi/kohozJp9dNs/0.jpg',
caption: 'beach video (caption)'
},
function(response) {
if (!response || response.error) {
console.log(response);
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
}
);
}
...and it shows the video's picture preview and caption:
...with these perms
publish_actions,read_stream,user_events,publish_stream
I did not need the name param like in your example.
Events created via the API
If you are creating Events using the API (not creating them using a web browser), try enabling the 'Events Timezone' migration:
App Dashboard > Advanced > Migrations > Events Timezone > Enable
See also announcement of that migration: https://developers.facebook.com/blog/post/2012/08/01/platform-migration--events-timezone-support/
Once the Events Timezone migration is enabled for your app, create a new event using the api, and then try posting the YouTube video story as written above in function post().