How to obtain not-friend's public photos - facebook-graph-api

I am trying to get user public photos (friend's friend). When i just browse facebook I see them, but I can't access them via API. Neither
SELECT created, link, caption, images, like_info FROM photo WHERE owner IN (SELECT uid FROM user WHERE username = "...") OR object_id IN (SELECT uid FROM user WHERE username = "kaja.szuminska") OR object_id IN (SELECT object_id FROM photo_tag WHERE subject IN (SELECT uid FROM user WHERE username = "...")) ORDER BY like_info DESC LIMIT 0, 100
nor
.../albums
nor
.../photos
nor
.../photos/uploaded
works.
Any ideas?

To access photos (public or not) you need permission. So it's only possible to access your photos (using user_photos permission) or friends' photos (using friends_photos permission).
If you want to scrape public photos, you can only do so by checking the user's public feed. I.e. making an API call to: https://graph.facebook.com/{user_id}/feed and then filter through the entries to see if any photos were posted.

Related

How to get a django instance to have one to many users relation

I have a company table as follows:
class Company(models.Model):
users = models.ManyToManyField(settings.AUTH_USER_MODEL, default=None)
My plan is that a given company instance can have more than one user account tied to it.
But from above, when a company is created, the users field is ending up with all the users in the users table.
That is not I want. I want that users are manually added rather than just populating the field with all users in the database:
How can I set this up so that a given company instance can only have the users added to it rather than all database users?

How to implement two authentication layers in django

I have a web application for businesses. Upon login, a user (the manager of the business) can view tables with information about their business.
userID 1->* rows in a MasterTable,
userID 1->* rows in a ForecastTable
I need to change it so an owner of multiple businesses can log into the account for a specific business and edit the same information that the manager can.
I was thinking about changing the database schema to something like this:
userID - businessID 1-* rows in MasterTable, rows in ForecastTable
Should I have 2 login pages, first for the userID, then the businessID. Then all the columns in the database only reference the businessID, so different users can edit the same data.
Or the same login form makes the user enter a businessID, and their username, then depending on which businessID they enter, it logs into that page?
I'm not sure what is the best practice to implement something like this.
Here is what my django model looks like:
from django.db import models
from django.contrib.auth.models import User
class MasterEntry(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
date = models.DateField()
cutoff1 = models.IntegerField(default=0)
cutoff2 = models.IntegerField(default=0)
rooms_sold = models.IntegerField(default=0)
is_blackout = models.BooleanField(default=False)
class ForecastEntry(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
date = models.DateField()
rate = models.IntegerField(default=0)
A user has hundreds of these 'master entry' and 'forecast entry' rows. I query the database for the rows and create a table in the front end.
You don't need two layers of authentication.
For instance, a user which is not admin only can view business he owns, this is achieved with a simple filter in the view displayed the mentioned list of business.
And you could render each business name as a link that then shows a list of MasterEntrys in it.
This is more a problem with information layout.
Conclusion:
Show a page only with business belonging to the authenticated user.
Superuser can see all business.
You can click a business entry in order to view/edit/delete any of the MasterEntrys it contains.

Django 2.x - filter redirects based on relational database content

I have an app I am developing that has 2 types of user (A & B) and I have a page that I want to redirect users that are not authenticated and not type B. The user type is set in a relational database.
My two db tables for this are
User - pk, etc...
Profile - pk, uid (user pk), account_type
What I have done so far:
I have already used #login_required in my views.py doc to verify authentication successfully.
I can filter for the content where pid is set manually:
Profile.objects.filter(user__pk=1)
And I can get the current user id with request.user.id
What I am struggling with
What I have attempted to do is create a conditional, where I am using the request.user.id with the filter to find that user and then verify account type. I am not sure how to pull the account_type and at this point my code is becoming a mess, and probably ineffective. I've searched for this, but everything I have found using the keywords I have here has revealed different problems than what I am trying to solve.
Edited additional info
I have 2 apps at use here, 1 is accounts one is listings, the page I am doing this for is for posting a listing, that is in the listing app; I only want one type of user (B) to be able to post it.
in the accounts I have this class:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
location = models.CharField(max_length=30, blank=True)
account_type = models.CharField(max_length=30)
In the listing app I have not yet created a relevant model, my understanding was that this filtering would happen in the view.
In the view I am doing:
#login_required
def post(request):
current_user = request.user
if : #here is where I want to filter, but haven't been able to get it to work
else:
return redirect('index')
You will get the account type value directly as
account_type = request.user.profile.account_type
So, you could able to do the stuff according to the account_type value as below,
#login_required
def post(request):
account_type = request.user.profile.account_type
if account_type == "B"
# do your stuff
else:
return redirect('index')
Starting from your model design, if your system has the criteria that one user has only one profile. Then set uid in Profile model as OnetoOneField so that you can easily access account_type by User.objects.filter(id=request.user.id).profile.account_type.
Else, if your system has the criteria that one user can have multiple profile. Then you first need to access it profiles, and select the particular profile by adding more filter, then you access the account_type:
User.objects.filter(id=request.user.id).profile_set.all() gives you user's all profile.
User.objects.filter(id=request.user.id).profile_set.get(your_filter) gives you user's particular profile.
User.objects.filter(id=request.user.id).profile_set.get(your_filter).account_type gives you access to particular user's profile's account_type.
One to One relationship description here
Foreign (many to one) key description here

FQL - how to get all the photos a person is tagged in

I am trying to build a page on our company web site that will show all photos our company is tagged in on facebook. Its the left "Photos of You" tab when in the FB photo page.
Is there a way to select just those pictures for a photo wall on our site?
I'm using FQL to help speed up queries on large albums.
Here is some FQL to select tagged photos for a specific user/page (where 123 is uid).
SELECT object_id, pid, aid, src_big, src_small, caption, like_info,
comment_info, modified FROM photo WHERE object_id IN (SELECT
object_id FROM photo_tag WHERE subject = 123)
Not sure if it helps, but I built an application to create photo slideshows for any Facebook user or page. Feel free to also give that a try, Slideshow App

django multiple related_name() search filter

I have a profile.
class UserProfile(models.Model):
user = models.ForeignKey(User, related_name="%(class)s", unique=True)
providers = models.ManyToManyField(ServiceProvider, related_name="%(class)s")
class ServiceProvider(models.Model):
name = models.CharField(max_length=200, null=False, default="ims")
How do I get to the user object with just having the profile object.
Can I do: (assuming I have my service provider object)
provider.userprofile.user.get() // or something like that.
I'd like to do that in one sql query. So if I had just the pk of the provider, it would be great to get to the user profile and/or the user that holds that provider.
Since your User is just a foreign key, all you need is provider.userprofile.user
If you don't want that to incur a second SQL query, you can just use the select_related option when selecting your profile, like:
UserProfile.objects.get(pk=<the_id>,select_related=True)
As written, your models don't provide a trivial way to get from the provider to the User, since there is a ManyToMany from the ServiceProvider to the UserProfile. You'll have to get the set of UserProfiles associated with the provider, get the one you want, and then proceed to get the User as above.