Facebook Media Attachment - fallback URL for 'music' type? - href

I'm using Facebook's Legacy REST API to publish MP3 media attachments to users' streams (as the new Graph API does not yet support audio). This renders the audio in Facebook's own media player as expected. However, because the player is a Flash component, it doesn't render on iOS devices and prompts for a Flash upgrade. I'd like to provide a fallback URL instead so the user can click through to an external site with an HTML5 audio player instead.
Is there a way of doing this? Supplying the href parameter in either the attachment object:
access_token = 1234567890.....,
format = 'json',
privacy = {
value: 'EVERYONE'
},
message = 'Message goes here...',
attachment = {
href: 'http://www.google.com',
media:[{
type:'mp3',
src:'http://www.looptvandfilm.com/blog/Radiohead - In Rainbows/01 - Radiohead - 15 Step.MP3',
title:'15 Step',
artist:'Radiohead',
album:'In Rainbows'
}]
}
or in the post object itself:
access_token = 1234567890.....,
format = 'json',
privacy = {
value: 'EVERYONE'
},
message = 'Message goes here...',
href: 'http://www.google.com',
attachment = {
media:[{
type:'mp3',
src:'http://www.looptvandfilm.com/blog/Radiohead - In Rainbows/01 - Radiohead - 15 Step.MP3',
title:'15 Step',
artist:'Radiohead',
album:'In Rainbows'
}]
}
does not seem to have any effect...
Am I therefore restricted to using the flash media type, supplying my own SWF player and image?

You can try the action_links array property on the post object to add a custom link for the user.
action_links = [("text":"alternate site link text here","href":"alternate url here"}]

You could try something like YepNope to test for iOS and load a different script based on the test.
yepnope({
test: '<test for iOS here>',
yep: '/scripts/scriptDefiningUrl.js',
nope: '/scripts/scriptDefiningFallbackUrl.js',
callback: function (url, result, key) {
alert('scripts loaded!');
}
});

Related

Facebook API not returning media source any more, how to get video links?

Sometime in the past month or so my app broke because I can no longer retrieve videos from the Facebook accounts I have access to. I use the https://graph.facebook.com/v10.0/{page-id}/published_posts endpoint to get all the posts and I include the attachments to those posts. Here is a video post from the response:
{
full_picture: "https://scontent-sof1-1.xx.fbcdn.net/v/t15.13418-10/52285035_2234305973503753_1707934143716786176_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=ad6a45&_nc_eui2=AeFnVEo3_0GBN3Z0ArKuyCC4PTctiml3Kak9Ny2KaXcpqfKpYLmuK7xAuPYTdTHOo-Rl5ZFJIsozhkhH2MI5T0OD&_nc_ohc=ZGkoZa1Nb98AX-by7TS&_nc_ht=scontent-sof1-1.xx&edm=APyxFHYEAAAA&oh=cf6f755c7a512dd74540343473b8e015&oe=611FF12B",
picture: "https://scontent-sof1-1.xx.fbcdn.net/v/t15.13418-10/s130x130/52285035_2234305973503753_1707934143716786176_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=ad6a45&_nc_eui2=AeFnVEo3_0GBN3Z0ArKuyCC4PTctiml3Kak9Ny2KaXcpqfKpYLmuK7xAuPYTdTHOo-Rl5ZFJIsozhkhH2MI5T0OD&_nc_ohc=ZGkoZa1Nb98AX-by7TS&_nc_ht=scontent-sof1-1.xx&edm=APyxFHYEAAAA&oh=f8f27b8ad553f2099ade862250868929&oe=611FDA5A",
message: "Plurato Sailfin u HRT-ovoj emisiji More",
permalink_url: "https://www.facebook.com/239543599886541/posts/563119407528957/",
created_time: "2019-03-10T15:58:31+0000",
attachments: {
data: [
{
media: {
image: {
height: 406,
src: "https://scontent-sof1-1.xx.fbcdn.net/v/t15.13418-10/s720x720/52285035_2234305973503753_1707934143716786176_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=ad6a45&_nc_eui2=AeFnVEo3_0GBN3Z0ArKuyCC4PTctiml3Kak9Ny2KaXcpqfKpYLmuK7xAuPYTdTHOo-Rl5ZFJIsozhkhH2MI5T0OD&_nc_ohc=ZGkoZa1Nb98AX-by7TS&_nc_ht=scontent-sof1-1.xx&edm=APyxFHYEAAAA&oh=ad3c1789fa9e72210e2bcaf23b39ea9c&oe=61208A3C",
width: 720
}
},
media_type: "video",
url: "https://www.facebook.com/HRTvijesti/videos/1271130086359640/"
}
]
},
id: "239543599886541_563119407528957"
},
It used to be that I would get a link to an actual video. I looked through my code and the part that extracts the url is:
const getFileUrl = (apiResult: Services.FacebookService.ApiPostListResponse) => {
if (apiResult.attachments) {
if (apiResult.attachments.data[0].media.source) return apiResult.attachments.data[0].media.source
else if (isYoutubeLink(apiResult.attachments.data[0].url)) {
return getYoutubeLink(apiResult.attachments.data[0].url, true)
} else return apiResult.attachments.data[0].media.image.src
} else return apiResult.full_picture
}
Apparently there used to be a "source" property under media but I can't seem to access that any more. I need a link which I can use to paly a video in a HTML video element. Is there any way of getting such a link now? I couldn't find it by browsing the documentation or by playing with the graph explorer. The attachments.data.url field is a link to a video but not to a video file, just a page that has a video inside it and I can't use that.

Upload attachment failure Facebook Attachment Upload API

I am trying to add an attachment to my message via facebook attachment upload API.
I am sending from a page (that I am an admin of) to a user that has sent message to my page.
Simple text messages are sent and also attachments as type 'file' is also working correctly. But when I put in 'image' or 'audio' as an attachment, the facebook sends response:
error: {
message: '(#100) Upload attachment failure.',
type: 'OAuthException',
code: 100,
error_subcode: 2018047,
fbtrace_id: 'AzfHWxf3AnikXiCCC-hYJOu'
}
Here is my code:
let messageData = {
message: {
attachment: {
**type: "image"**,
payload: {
is_reusable: true,
url: <url of the image>
}
}
}
}
let data = await axios.post(`https://graph.facebook.com/v8.0/me/message_attachments?access_token=${accessToken}`, messageData)
Upload attachment failure. A common way to trigger this error is that the provided media type does not match type of file provided int the URL
from official docs

Headless Chrome Puppeteer Skip Logging In To Twitter Using Cookies?

Is it possible to skip logging in to twitter by setting cookies?
I tried to copy an paste what I got from "document.cookie" in web console but that gave me the error Invalid parameters name: string value expected
await page.setCookie({
personalization_id: "v1_VDBAhQo+RMCSceKUBXfs3w==",
guest_id: "v1%3A150575165219105300",
ct0: "d9343a3b062832b6ec23a84747e518b3",
_gat: "1m",
ads_prefs: "HBERAAA=",
remember_checked_on: 1,
twid: "u=908918507005456384",
lang: "en",
tip_nightmode: true,
_ga: "GA1.2.1275876041.1505751657",
_gid: "GA1.2.1311587009.1505751657"
})
The correct syntax for setCookie is not what you used, it's:
setCookie(cookie1, cookie2, ...)
where cookie is an object containing name and value keys, like
setCookie({name: 'lang', value: 'en'})
Remember to set the cookies before loading Twitter, or to reload the page after setting them, and everything should work.
async function addCookies(cookies_str, page, domain){
let cookies = cookies_str.split(';').map(pair=>{
let name = pair.trim().slice(0,pair.trim().indexOf('='))
let value = pair.trim().slice(pair.trim().indexOf('=')+1)
return {name,value,domain}
});
await Promise.all(cookies.map((pair)=>{
return page.setCookie(pair);
}))
}
this is my way to add cookies, cookies_str was copied from browser;

publish story using Object API

I am trying to publish stories from my server when people win a game into my web app.
I have folowed the documentation but i apparently do something wrong, here is the url and the datas object i pass into my POST call.
https://graph.facebook.com/'+user_id+'/points.win
var Datas = {
title: '500',
type: 'mygame:points',
image: 'http://mywebsite.jpg',
url: 'https://mywebsite.com',
description: 'YOU WIN !',
data: { rank: 326 },
'points': OBJECT_ID,
'access_token': TOKEN
};
I get the error: {"message":"Unknown path components: \/points.win","type":"OAuthException","code":2500}
I do have a "Points" object and a "Win" action on my app interface (and a "Win A Point" story).
I don't really know what i am doing wrong, also i am not sure my OBJECT_ID is right, i found a value close to my app_id at the end of the sample url by clicking "Get the Code" (on the points object) > Code for object > inside the object=...url=.../<here>... and i used it here but i didn't find where it's clearly said Object_id: <value> on developer.facebook.com.
UPDATE: I think the only way to get an object ID is to create it thought the Object API, i am going to try this way, i'll keep you updated if it's works or not.
I have created the object through the Object API and it works fine !

facebook create_event posts on my app's wall not the user's wall

i'm attempting to provide a facility on my site that allows a user to create a facebook event for their booking.
http://developers.facebook.com/docs/reference/api/event/
now im doing the correct process:
1) first getting authorisation from the user
https://graph.facebook.com/oauth/authorize?client_id=APP_ID&redirect_uri=http://urlimredirectingto.comtype=web_server
2) requesting for an access token with the "code" that is returned in step 1
https://graph.facebook.com/oauth/access_token
3) using the access_token to create the event ...
string facebookCreateUri = string.Format("https://graph.facebook.com/{0}/events", loggedInMember.FacebookUID);
var formData = new HttpUrlEncodedForm()
{
{"access_token", accessToken},
{"owner", loggedInMember.FacebookUID},
{"description", "nice event that should be on the owners wall"},
{"name", "event on the users wall"},
{"start_time", "1272718027"},
{"end_time", "1272718027"},
{"location", "rochester"},
{"privacy","OPEN"}
};
HttpContent content = HttpContent.Create(formData);
HttpClient client = new HttpClient();
var response = client.Post(facebookCreateUri, "application/x-www-form-urlencoded", content);
but the event is posted on my app's wall, not the user's wall. It shouldn't have anything to do with the authentication/access_token elements because i use the same process to post on the user's wall. (http://developers.facebook.com/docs/reference/api/status/) and that works just fine.
I came back with a solution, after a week of working at many features with Facebook SDK, it finally works!
protected void onPostEvent(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = new FacebookWebClient(CanvasAuthorizer.FacebookWebRequest);
dynamic parameters = new ExpandoObject();
parameters.description = txtEvDett.Text;
parameters.name = txtEvName.Text;
parameters.start_time = DateTime.Now.ToString("yyyyMMdd");
parameters.end_time = DateTime.Now.AddDays(1).ToString("yyyyMMdd");
parameters.access_token = CanvasAuthorizer.FacebookWebRequest.AccessToken;
dynamic eventDet = fb.Post("me/events", parameters);
litEvent.Text = String.Format("You have created the event with ID: {0}", eventDet.id);
lnkEvent.Visible = true;
lnkEvent.NavigateUrl = String.Format("http://www.facebook.com/event.php?eid={0}", eventDet.id);
}
}
For events, you have to request the create_event permission.
You should use /me/events to post on your events.
I user the C# SDK for Facebook from Codeplex - last version available for dld (aug 2011 - v5.2.1).
Good luck!
I don;t see in your request for Authorization any permission.. base permissions are not enough to do the postings.
i used:
https://www.facebook.com/dialog/permissions.request?app_id=MY_APP_ID&next=MY_APP_URL&display=page&response_type=code&canvas=1&perms=publish_stream,user_about_me,email
This is in the context of a canvas app. where MY_APP_URL is the url from facebook of the app:
http://apps.facebook.com/MY_APP_NAME_OR_ID
See extended permissions for events and check event's page in documentation
[EDIT] - I came back, sorry, now i did a test, and indeed, it works for me, but only of i post on my app's wall; even if i provided the 'user_events' permission i get this error:
The remote server returned an error: (403) Forbidden when posting on a user's wall.
This being said, i also subscribe to this question.