Facebook JS API, accessing public photos without authentication - javascript

I am looking to know is there a way to get a listing of photos in a specific album on a specific page (where both the album and page are public). Without the need to authenticate at a user level. I basically am looking to show a number of photos from an organisations page on that organisations website (however I dont want to show them all).
I have followed the examples here:
https://developers.facebook.com/docs/javascript/quickstart
and here:
https://developers.facebook.com/docs/graph-api/reference/v2.7/album/photos
but I cant appear to get a listing of photos. Is it possible to get such a listing without the user authenticating with FB first?

It is possible, you can use an App Access Token if the Page is not restricted by age or location, or a Page Access Token if the Page is restricted. App Tokens and Extended Page Tokens are valid forever, so you can just store those on your server to make the API calls. No additional user authorization needed.
Information about how to generate the different Tokens can be found here:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Related

Pull data from CRM online using Web API

I've created a webpage that will be used as a survey for end users to submit a review of how the helpdesk technician did with resolving a ticket. I've built the webpage using HTML, CSS, JS, and PHP. The page currently needs to pull 2 things from Dynamics 365: Users name and the company. I currently pass the ticket # via the URL which I plan to use as the value in a lookup (somehow).
I think that I need to use the Dynamics API somehow to get access to pull data from the form but I am not sure how to go about that. I found this post online https://functionalthoughts.com/dynamics-365-web-api-retrieve-data-javascript/
which I think is only for web resources created inside of CRM.
Here is an image of what I currently have:
Image
and the value that I have passed via URL Image2
The end goal would be to pull the value of the name and company fields in Dynamics 365 Online.
Without full context of your application, I can only give you high level pointers.
Before anything,
You need to authenticate to Dataverse (the engine that is hosting the data your after). That means you need a an identity + JWT Token to auth.
This is the more complicated part, depending on how your managing access to your site and if your intending to allow dataverse to manage data access security.
To do that, in php, your going to want to start here: https://learn.microsoft.com/en-us/azure/active-directory/develop/reference-v2-libraries#web-application and read up the Python path for MSAL.
Once you have that you will either use a S2S app ( ConfidentialClient app ), or user identity auth ( publicclient app. )
For explanation sake, I am going to assume that you created a Confidential app to work with. In Dataverse this type of login identity is called an "Application User"
Now you need add the application user to Dataverse and grant it permission to read the data you want. You should work with the admin of the dataverse instance to get that setup. if your trying to solo it :) there is a good blog on how to do this here: https://powermaverick.dev/2020/08/10/create-application-user-in-dataflex-pro-cds/ Dont forget to grant your user a security role that can access the data your after.
Next,
You said you want to query by Ticket ID, again assuming that ticket id is in dataverse, you need to create an alternate key for the field that contains the ticket to be able to query on it.
you can find info on how to do that here: https://learn.microsoft.com/en-us/powerapps/developer/data-platform/define-alternate-keys-entity
Ok, now that you have a user to work with and can create a token, and you have an alt key on the column your trying to query on, you just need to form the query to dataverse.
General info on how to form and call queries in dataverse can be found here https://learn.microsoft.com/en-us/powerapps/developer/data-platform/webapi/query-data-web-api a specific example of retrieving via alt key can be found here: https://learn.microsoft.com/en-us/powerapps/developer/data-platform/webapi/retrieve-entity-using-web-api#retrieve-using-an-alternate-key
Now that you have all the setup done, and once you have formed your query, you will need to generate the token and add it to the authorization header of the request and send over.
That should get you data back.

Fetch posts from Facebook page using FB API

Up until this summer, I had a website (not my website) which was fetching it's responding fb page posts and was displaying it on a page.
I was doing it using the app-token, which now doesn't work since it now requires Page Public Content Access to get those data, which in turn requires it to be registered as an app, which is beyond the scope of this.
I tried creating a non-expiring user-access token, but they seem to expire after 3 months, no matter the "trick" I tried using.
Is there any suggestion of how I can get over it?
Maybe an automated api call that would refresh the token with no user interaction?
You can either use a Page Token (NOT a User Token) for the Page if you manage it - but it will expire. There is no way around that. OR you apply for Page Public Content Access so you can use an App Token.
Auto-refreshing would make the whole point of expiring Tokens pointless, you need user interaction for that.
So, I did it!
Now the how: I did it with the manage_pages access, not with Page Public Content.
I went back and forth a total of 5 times to get this to pass and a bit over a week.
First of all Page Public Content is only allowed by Facebook when you want to analyze data from other pages as well, so you better not mess with it.
What I had to do to get the request approved is specify on your application for requesting the access that there is no login, provide a copy of your code on the description and I also included a url where it was working with a user generated token through javascript, so they could review the code through a web debugger.
After that you get a manage_pages token which you can use to fetch your pages posts
I really hope some of those things were an overkill, but, like I said, I had to submit a review a total of 5 times, so on the last try I went all in...

How can my website retrieve my Facebook page Live Videos?

If I go to the Graph API Explorer, get a User Access Token, and then go to /<page-id>/live_videos I can return a list of live videos from that page, including the status (VOD aka past, or LIVE) and the embed_html.
This is great but the problem is this User Access Token will expire. I want to be able to get this data as part of my website to show visitors whether we are live or not, and if so give them an option to open the video right there on the site. It shouldn't be something a user has to login in to allow my app to access FB on their behalf.
So I tried using an App Access Token which I got by using the App ID and App Secret of my page's 'Facebook App' as described in the Facebook docs here... but the Token that I get from this does not work; it tells me A user access token is required to request this resource.
Why must I get a User Access Token when it's my App (aka my website) that wants the data?
Honestly I didn't think it would be hard to get this information since it is a completely public page; I would have guessed you don't even need to authenticate, but probably just some need sort of identifying token for your app for rate limiting, etc. Is there any method like that?

Facebook API - Pages - Get names of subscribers

I want to get the names of the subscribers of my facebook Page (I want to thank them and develop a single page website who mention each of them).
I use jQuery?
I have not find anything in the doc.
There is no API to get the fans of a Facebook Page. If you mean the followers of your User profile, that is not possible either. You should actually treat them as if they would be anonymous.
Btw, you would not be allowed to put them on an external website without their permission anyway.

OAuth and Facebook page tabs

I'm in need of more of an explanation than an answer, per se - I'm building a page tab, which will pull certain images from a particular album belonging to the page. This does not require an access token, so there is no need to ask for permissions from visitors.
I can add like/share options which also work fine without an access token or authorisation.
How do I get basic user info (id, name etc) without requesting authorisation? It's a page tab, on Facebook, so therefore the visitor must be logged in already.
Just seems counter intuitive if I have to request permissions to perform what is essentially pretty standard actions.
I'm using the javascript SDK.
It's a page tab, on Facebook, so therefore the visitor must be logged in already.
The user may be logged in to Facebook – but he is not necessarily connected to your app (yet). And you need him to be, to get his user id.
Make a call to FB.login without asking for any permissions in the scope parameter – that’ll prompt the user to connect to your app, giving it only “basic” permissions to read his personal data. That’ll give you his user id in the response.authResponse (and also will lead to his user id being included in the signed_request next time he visits your page tab).
After that, you can get his basic user info be calling /me via the Graph API.

Categories