private RSS feed items - feed

What are the best methods to create private RSS feeds? I have some public feed items and some private feed items. When user clicks on private feed item link, he needs to be authenticated before viewing the post.
Thank you.

You can use HTTP authentication (401 + WWW-Authenticate header)
You can create unique, unguessable feed URLs. This is easiest for users, as it "just works" with any feed reader without extra step.
Ideally you should allow user to invalidate all those URLs from your website (in case private feed URL "leaks")
E.g.: store random string (uuid/hash of random data) in your users table, when serving feed look up user using this string. When user wants to invalidate feed URLs, generate new random string.

Related

Redirect Private Wordpress Posts to the url held in a specific custom field on the taxonomy for that post

We would like to keep the ideas we have previously presented to (non logged in) clients, but which are no longer "current". We set them to being private WP posts, so that they are no longer available to non logged in users. However, we would like to redirect anyone who clicks on that original link to a page which shows all of the currently active ideas instead.
Research led me to the solution below, but in our case we need to redirect to a specific url in each case. Our theme (the amazing Total theme from WP Explorer/AJ) does have a field for the redirect url to be entered at post level, but actually the value of the url is determined by the value of a custom taxonomy on a post ie all posts with that Taxonomy should redirect to the same url in all cases.
add_action('template_redirect', 'your_theme_private_posts_redirect', 99);
function your_theme_private_posts_redirect()
{
if (is_single() && 'private' == get_post_status(get_the_ID())) {
wp_safe_redirect(home_url());
exit();
}
}
Credit https://stackoverflow.com/questions/68954429/wordpress-how-to-redirect-private-custom-post-types
I understand that the above code would redirect all private posts to the home url, but how can I adapt it to do the following:
a) Only to apply to non logged in users and b)to set the url to be the value held in the redirect field on the post OR (better still) a custom field on the agency_artist custom taxonomy for that post. Hoping someone can help!

Retriving data from facebook events

I have to create an webpage where i need to show all the events from the past or upcoming ones from an facebook page. I have to retrive the title, description, image, time and place of every single one and make a box with it.
After that, i have to retrive all the interested people.
I'm a beginner trying to make big things! Thank you very much.
This isnt a simple problem - I have just done this so will give you a start.
You need to use Facebooks Graph API to get the data, you will need to read up on the Graph API and how to use it. Documentation can be found here. Its worth noting due to a security breach the API isn't offering all of its services to new developers currently but you can get most - read about this here.
You can query the API using any language but I suggest do it with python and use the requests module. Alternatively you could use this SDK which makes things a lot easier, trust me! With the SDK you need to get a user access token which you can get from here.
SDK
With the SDK its possible to do this
import facebook
graph = facebook.GraphAPI(access_token="your_token", version="2.12")
event = graph.get_object(id='event_id',
fields='attending_count,declined_count')
print(event['attending_count'])
print(event['declined_count'])
You can add more fields to the fields list. However you can use any language you choose to request the data, as you can just construct your own URL's.
Graph API & Requests
This is how I did it in python using requests to query the API.
import requests, json
#Make a requests session to fetch data from URL's
session = requests.Session()
session.mount('https://', requests.adapters.HTTPAdapter(max_retries=10))
#API base URL
baseUrl = 'https://graph.facebook.com/v2.11/'
#Fields you want to get
fields = ['id', 'name', 'start_time', 'end_time', 'description', 'place']
#replace CLIENT_ID and CLIENT_SECRET with ones from a facebook app (make one)
tokenPath= 'oauth/access_token?client_id={0}&client_secret={1}&&'\
'grant_type=client_credentials'.format(CLIENT_ID, CLIENT_SECRET)
#Get the generated token
token = session.get(baseUrl + tokenPath).json()['access_token']
event = session.get(baseUrl, params={
"ids": "event_id",
"fields": ",".join(fields),
"access_token": token,
}
).json()
print(event["name"])
print(event["place"])
You can make a facebook app here which is where the CLIENT_ID & CLIENT_SECRET come from.
Why would you use URL requests and not the SDK?
Using the SDK the generated user access tokens expire every day, its possible to extend them but only for 60 days. If you want to use the SDK it has a method built in which allows you to extend the token, in order to extend the token you also need to create a facebook app. Its also possible to extend tokens using this website, though I cant vouch for its security - it could potentially access and exploit your data.
To extend the token with SDK:
import facebook
graph = facebook.GraphAPI(user_access_short_lived_token)
extended_token = graph.extend_access_token(app_id, app_secret)
print(extended_token)
Using the URL approach, you create a client access token at runtime (read about user access token vs client access token here) and the token is valid so long as your app is active. So if you are going to use this a lot or want to create it and not have to change/extend tokens then use the URL approach.
Hope this gets you started.

github users API Paging not work

when using github users api to return users data through
https://api.github.com/users?page=6&per_page=2
return the same data every one although change page parameter value and per_page
why this and how to fix to change different data
i try to edit header request and add this header
Name Link
Value <https://api.github.com/users?page=1&per_page=2>; rel="next",<https://api.github.com/users?page=50&per_page=2>; rel="last"
But Still not working
After my search
now Github use API V3 and if you want return users with paging you can use this
https://api.github.com/users?since=1&per_page=100
Instead of using "page" and "per_page", that endpoint uses "since" and "per_page".
The since parameter says from which user ID the API should start listing users. For example:
https://api.github.com/users?since=1&per_page=100
will start listing users from the user with ID 1, and
https://api.github.com/users?since=10001&per_page=100
will start listing users from the user with ID 10001.

API call to retrieve all public information of Facebook user?

I know I can call each individual field via something like
/---ID----?fields=gender,languages,age_range,bio,birthday,education,email,hometown
Is there a quicker way than listing every single field?
It is ok if the user has most of these fields locked down with their privacy settings, I just want it to pull what is available.
just try:
https://graph.facebook.com/{{ username or uid }}?access_token={{access token goes here}}
Example:
https://graph.facebook.com/zuck?access_token=###
will give all the public information available for that user.

Facebook Graph API and Generic Access token

If I understand correctly, the Graph API enables access to public pages using a generic access token. I'm finding however that many public pages are not returned in search results when using this type of token vs. a user token. I don't want users to have to go through an OAUTH dialog just to retrieve the basic properties of a public page.
This example below returns a result when using any user access token but no results when using a generic access token:
What am I doing, or understanding, incorrectly?
https://graph.facebook.com/search?q=OSullivansHerndon&type=page&access_token={myuseraccesstoken}
https://graph.facebook.com/search?q=OSullivansHerndon&type=page&access_token={APPID|APP SECRET}
You can get a generic access token for your app that will let you look at requests where you would otherwise need an access_token= parameter in the Graph call. You don't need to authenticate users as the access token is for the application.
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&
client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
example:
https://graph.facebook.com/nike/posts?access_token={response from above call}
I suspect you need a user access token to use /search as search results use social context. If you have the page id, you can load that without any access token by just hitting /id
I dont think you can get this to work without a user access token. From my limited OAUTH is the only way forward.
By specifying GRAPH API user token, you simply meant that you are using user preferences and information .
if your intention is to fetch some public page information , then you need that page userid or username . And , if you are intention is to grab all the public data which is available for your particular user , then you have to pass oAUTH system,Since indirectly you are accessing his information which is meant public under some facebook govern rules .
Accessing public page by providing user id
https://graph.facebook.com/19292868552
By writing the id of that page,you ca access its information. Now the question is how to access the id of that particular page, Manually just visit that page --> photo album . on the top of that page,you will see something like "Album Videos" . Just visit any of that link.now see,woola the id of that page is visible to you . something like this url
http://www.facebook.com/media/albums/?id=176101909092314
And btw,if you are interested in performing search , then you need to specify user token. facebook do some algorithmic search for all users and track user activities . So , the result will not always the same for you and me , as an example .