Batch retrieval of friend profile photos - facebook-graph-api

I have successfully retrieved up to 50 user's profiles using the batching method. I attempted to use the same process to retrieve these user's profile photos, but get an error 302. I see that there is a URL pointing to the photo returned in the result, but using that to retrieve each photo would defeat the purpose of batching, which is to retrieve all at once and prevent repeated HTTP requests. Is it possible to retrieve these using the batching in the Facebook API?

Try FQL:
SELECT pic_square FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me())
...where pic_square can be one of pic_small, pic_big, pic_square, pic
That'll give you URLs for the corresponding user's profile picture at the given size.
e.g.:
https://developers.facebook.com/tools/explorer/?method=GET&path=fql%3Fq%3DSELECT%20pic_square%20FROM%20user%20WHERE%20uid%20IN%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29

Related

DynamoDB table design for social network

I got a thinking-problem in DynamoDB.
My structure is looking as following:
primary key = "id"
sort key = "sort"
I have posts, users and "user A following user B" relationships.
Users:
id=1234
sort="USER_USER_1234"
name="max" (for example)
-
id=3245
sort="USER_USER_3245"
name="tom"
Post:
id=9874
sort="POST_POST_1234 (because its created by user id 1234)
createdAt=1560371687
Following:
id=1234
sort="USER_FOLLOW_3245"
--> tom follows max (but max not tom)
How could I design a query to get all posts by the people which tom(id=3245) is following? So in my case the post id 9874?
My approach was to put a GSI where sort is the primary key and id is the sort key (that i can query all people which user A is following), than get all the posts from the users (with help of the same GSI) and sort the result after a second index where createdAt is the sort key. The problem is that this needs much much querys (imagine user A would follow 10000 people and they all make posts). Is there a technique or design thinking approach which you could recommend for this situation? My second approach was to index the whole application table to elastic search and do a nested query. Would this make more sense? Or would you recommend using another type of database like AWS neptune?
There's a hands-on lab on aws about a similar problem - "a mobile application that includes a social network": https://aws.amazon.com/getting-started/hands-on/design-a-database-for-a-mobile-app-with-dynamodb/4/
Brief description:
Users will upload photos through your application
users will want to find and follow friends
By following a friend, a user will receive notifications of the friend’s new photos
user will be able to message their friends
friends can view their photos
users can react to a photo with one of four emojis — a heart, a smiley face, a thumbs up, or a pair of sunglasses.
When looking at a photo, users should be able to see the number of each type of reaction a photo has received
The model has the following entities: User, Photo, Reaction, Friendship.
A User can have many Photos, and a Photo can have many Reactions. Finally, the Friendship entity represents a many-to-many relationship between Users, as a User can follow multiple Users and be followed by multiple other Users.
Access patterns
Based on the business requirements, these are the access patterns identified:
User
Create user profile (Write)
Update user profile (Write)
Get user profile (Read)
Photo
Upload photo for user (Write)
View recent photos for user (Read)
React to a photo (Write)
View photo and reactions (Read)
Friendship
Users can follow friends, view updates on their friends’ activities, and receive recommendations on other friends they may want to follow.
A friendship is a one-way relationship, like Twitter. One user can choose to follow another user, and that user may choose to follow the user back. For our application, we will call the users that follow a user “followers”, and we will call the users that a user is following the “followed”.
Based on this information, we have the following access patterns:
Follow user (Write)
View followers for user (Read)
View followed for user (Read)
On the Friendship entity, we have an access pattern that needs to find all users that follow a particular user as well as an access pattern to find all of the users that a given user follows.
Table Design
Because of this, we’ll use a composite primary key with both a PK and SK value. The composite primary key will give us the Query ability on the PK to satisfy one of the query patterns we need:
Entity PK SK
User USER#<USERNAME> #METADATA#<USERNAME>
Photo USER#<USERNAME>. PHOTO#<USERNAME>#<TIMESTAMP>
Reaction REACTION#<USERNAME>#<TYPE> PHOTO#<USERNAME>#<TIMESTAMP>
Friendship USER#<USERNAME> #FRIEND#<FRIEND_USERNAME>
The Friendship entity uses the same PK as the User entity. This will allow you to fetch both the metadata for a user plus all of the user’s followers in a single query:
KeyConditionExpression="PK = :pk AND SK BETWEEN :metadata AND :photos",
ExpressionAttributeValues={
":pk": { "S": "USER#{}".format(username) },
":metadata": { "S": "#METADATA#{}".format(username) },
":photos": { "S": "PHOTO$" },
},
A secondary (inverted) index is useful to query the “other” side of a many-to-many relationship. This is the case for your Friendship entity. With your primary key structure, you can query all followers for a particular user with a query against the table’s primary key. When you add an inverted index, you will be able to find the users that a user is following (the “followed”) by querying the inverted index:
KeyConditionExpression="SK = :sk",
ExpressionAttributeValues={
":sk": { "S": "#FRIEND#{}".format(username) }
},
Extensions
What would be interesting is to tweak the design to support mega-popular users (having millions of followers).
Another interesting access pattern not mentioned here is the user feed - see all the photos that their friends have recently posted. This could be done with another table to contain this stream of data which gets updated whenever a friend posts something (find his followers, update their feeds...).
In Amazon Neptune, this would be something as simple as:
g.V(3245).E('post')
The above query would return an iterator, to all the vertices connected by the Edge label "post", starting from the vertex with ID "3245". You can firther tighten it up by either projecting specific properties (.property('name')) from those vertices or materializing the whole vertex (.valueMap()). This is just Gremlin syntax, and you can easily do the same using SPARQL as well, and Amazon Neptune supports both of them.
A bigger question for you is to evaluate all the types of queries you wish to perform on your data, and see if modeling it in a graph database makes sense. If it does, then you're better off using Neptune as opposed to something custom using a mix of other products. Querying/Traversing highly connected data, navigating through relationships etc are some of the classic usecases to use a graph data model.

Sitecore ECM op-tin and opt-out roles dates

I want to know is there any way to get user subscrition / unsubscrition to email campaign ?
Is it saved in one of databases/tables in MSSQL ?
If you use the approach with opting in and out being determined on the fact if user is in role, then it is stored in the aspnet_UsersInRoles table in your core database. This table does not keep the information when role was assigned to the user. That's why you cannot get information when user subscribed or unsubscribed to email campaign.
The only thing you can check is if user is in the role:
user.IsInRole(roleName)
The user's subscription is driven by the users role, but It is possible to get the users subscriptions in ECM, You just have to use the api.
You can get the contact from the email address:
string fullName = commonDomain + "\\" + Util.AddressToUserName(username);
var contact = Contact.FromName(fullName);
var subscriptions = contact.GetSubscriptions();
Once you have a contact you can call the GetSubscriptions() method which will return the recipient lists the user is signed up to. There are a host of other methods you can call on a contact and if there is a a way to get the date unsubscribed/subscribed it will be here.
If not reflect Sitecore.EmailCampaign.dll and keep looking! There might be some extra information in the automation states table in the Analytics database. More info on automation state here:
https://www.sitecore.net/learn/blogs/technical-blogs/sitecore-magnified/posts/2013/09/ecm-automation-states-magic.aspx
Also noticed there is a method GetUnsubscribersStatistics on the Sitecore.Modules.EmailCampaign.Core.Analytics.AnalyticsHelper class. This will have the date of unsubscription.

Facebook Graph API: get the photos in an album of a group

Before I ask give some information which i am already able to achieve:
I'm able to get the group feed in JSON format
I am accessing a group. I have got a long lived access token and i could access the feed.
Inputs I have are: group_id, acess_token.
URL USED:
https://graph.facebook.com/v2.1/{group_id}/feed?access_token={access_token}
The URL gave JSON formatted output of all the posts etc.
I'm able to achieve the albums of the group
URL USED:
https://graph.facebook.com/v2.1/{group_id}/albums?access_token={access_token}
The URL gave JSON formatted output of all the albums (their IDs, name, etc.).
What I'm NOT able to achieve:
URL USED:
https://graph.facebook.com/v2.1/{album_id}/photos?access_token={access_token}
URL USED:
https://graph.facebook.com/v2.1/{album_id}?fields=photos&access_token={access_token}
URL USED:
https://graph.facebook.com/v2.1/{album_id}/photos?fields=picture,source,name&type=uploaded&access_token={access_token}
{
"data": [
]
}
I even tried the above in the 'Graph API Explorer', I get the same output.
I have tried for various group ids to see if some group ids may be the source of the problem. But I get the same output as shown above.
I have gone through all related questions on Stack Overflow. I am using the same URL formats as mentioned in the posts. They say that they can see the photos' data in JSON.
Due to permissions restrictions it is not possible to retrieve all photos from group albums unless the user uploaded those albums themselves.
The Graph API reference mentions that one of the following is necessary to retrieve a regular album:
Any valid access token if the album is public.
A user access token user_photos permission to retrieve any albums that the session user has uploaded.
Oddly, the /{group_id}/albums edge, is undocumented. Here's what I've learned from experience about accessing group albums:
A user access token with user_photos permission will allow access to album information and photos for albums that user uploaded.
Any attempt to access any album the user did not upload (including public albums in public groups) will return album data, but not photo information.
You were using the correct queries. For completeness I will restate them here.
Album information
https://graph.facebook.com/v2.1/{group_id}/albums?access_token={access_token}
Photos
https://graph.facebook.com/v2.1/{album_id}?fields=photos&access_token={access_token}
You can still access photo attachments (but not albums) off of /{group_id}/feed

Ability to add user-data to Facebook post and use it while quering thru FQL or Graph API

Is there a way to add user-data (a number or a string) and use it while querying posts from the stream of that page ?
Essentially I am trying to make posts with certain attributes on a Facebook page thru an App and would like to query the stream (newsfeed) on that page using FQL or Graph API and just select the specific posts based on the attributes added to the posts.
SELECT post_id FROM stream WHERE **user_data** ='tag-specified-with-post' app_id='APP_ID'.
Thanks for your help.
Use FQL to get posts from your app. This query will get posts made in the account of the user by the Photos app:
SELECT app_id, post_id, actor_id, target_id, message FROM stream WHERE filter_key ='owner' AND is_hidden = 0 AND app_id='YOUR_APP_ID'
Replace that app_id with yours. And replace filter_key with 'others' to get other people's posts that the user can view.

Get my UID using FQL

I need to get my UID using a simple FQL query, for some reason it returns an empty page.
This is my query:
https://api.facebook.com/method/fql.query?query=SELECT uid FROM user WHERE uid=me()
me() returns the current connected user. So you need to append an access_token:
https://api.facebook.com/method/fql.query?query=SELECT uid FROM user WHERE uid=me()&access_token=XXXXXX
P.S.: Facebook has just released a Graph API endpoint to query FQL fql, so you should be able to do something like:
https://graph.facebook.com/fql?q=SELECT uid FROM user WHERE uid=me()&access_token=XXXXXX
(unfortunately, for some reason it's not working on the Facebook Graph Explorer)