Post YouTube video into a Facebook Event Wall - javascript

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

Related

Expo notification click to action

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

Implement a window to log in LinkedIn in MVC 5

I'm working in an mvc5 application where users have their own profiles, there should be a button which would open a pop-up window so that an individual user logs into LinkedIn as to sync his/her LinkedIn profile picture with our site's.
I don't think it can be implemented with modals because there's page navigation involved, so I thought about what I stated previously: a pop-up, is there a way to do this via javascript? Like, opening a pop-up and expecting a response to determine if the user logged in. If there is a better way, any info would be greately appreciated, my aim is to be able to sync the profile picture without having the user to get redirected to linked in from their profile view, I want them to change it from there and not leave the view. Is it possible to do so?
EDIT: To clarify, getting the image URL is not a problem, what I need to do is get the url from the profile window, which comes from the popup window.
You should have a look at their API it is well documented. You'll need additional permissions to retrieve the full profile. LinkedIn Profile API
I ended up using the Javascript SDK:
$('#btnSyncLinkedInPicture').on('click',
function () {
var myID = 3;
IN.User.authorize(function () {
IN.API.Raw("/people/~:(picture-url)").result(function (data) {
$.ajax({
type: 'GET',
url: '/MyController/MyAction?pictureUrl= ' + data.pictureUrl + '&id=' + myID,
success: function (result) {
$('#imgProfilePicture').attr('src', result);
}
});
}).error(function () {
});
});
});
First, we authorize the user which will open a pop-up window so that we authenticate, the SDK will abstract us from the OAuth process. After authenticating, we may want to write a callback function, in which we can already perform REST calls via the SDK methods (you can do it elsewhere as long as you have successfully authenticated).

Soundcloud SDK - load track from url

So I did a tutorial on Soundcloud SDK through CodeAcademy here and wanted to take the knowledge I learned from that and put it on Codepen. But I want to use a different track than the one they use in this tutorial - specifically this song https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download.
I read that /resolve was a good approach to get the trackid but it's not working. I get 403 Forbidden in the console.
SC.get('/resolve/?url=https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download&client_id=3596a42d6242b9c1ee76740a7771d33a', function(track) {
console.log(track); // returns null
});
Here is my codepen. Please help me load this track for my basic SoundCloud SDK audio player. Thanks
Your code is correct and even works with some tracks, for example the ones from the documentation.
You're encountering a problem that I found personally should be emphasized in their documentation. The API access for this track has been disabled (even if the widget is enabled), therefore your have not right to query this track using the API and it returns a 403 Forbidden HTTP status code.
This is described in the Linked Services part of the SoundCloud terms of use:
You can limit and restrict the availability of certain of Your Content to other users of the Platform, and to users of Linked Services, at any time using the permissions tab in the track edit section for each sound you upload, subject to the provisions of the Disclaimer section below.
You can check in your code if any error like this one was encountered while fetching the track informations and depending on the success or failure, continue with the correct action:
var clientId = 'CLIENT_ID';
SC.initialize({
client_id: clientId
});
var songUrl = 'https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download';
SC.get('/resolve?url=' + songUrl + '&client_id=' + clientId, function(data, error) {
if (error === null) {
console.log('Do something like playing the song.');
} else {
console.log('Print an error message?');
}
});

Facebook - FB.UI feed and share dialog

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.

Facebook - Posting to a Group page

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

Categories