Facebook like an object - codeigniter

Need help with Facebook SDK Php Facebook Like.
My website fetches Logged in FB User's Timeline and user can Like posts in his timeline.
Posting Likes works for me successfully. But my question is how should I know he had already liked the post.
I want to show Like button if he has not liked that object and unlike button if he has already liked it.
PS: I tried collecting all the list of users who liked and then compared it with logged in user's fb id, but this method takes long time if likes are more than 10k.
Is there any other methods to accomplish this task.
I am using facebook-php-sdk-v4-4.0-dev
PS: My code for showing his feed is:
(new FacebookRequest($session, 'POST',"/me/feed", $params))->execute()->getGraphObject()->asArray();

The only solution available now is looping through the list of likes like you do , as of now .
there is another solution using FQL
select user_id from like where object_id=your object_id AND user_id=me()
but the problem is that he LIKE table only considers videos, notes, links, photos and albums, not posts.
check facebook fql like documentation . also note that fql is on track for full deprecation .

May be this will help you
$fql= "select user_id from like where object_id=REQUIRE_OBJECT_ID_HERE AND user_id=me()";
$request = (new FacebookRequest($session, 'GET', "/fql?q=$fql"))->execute()->getGraphObject()->asArray();
Change REQUIRE_OBJECT_ID_HERE variable to the id that you need.

Related

Discord.py | How do I get a User Tag from an ID?

I am programming an entertainment bot with discord.py, and I want to code a function that allows you to look at other users' in game money and stuff with replit databases. Since making data with a user tag is inefficient since people change their usernames and tags all the time, I am using IDs. I am trying to find a way to get a user tag (eg. Dude#1234) from a user number id (eg. 871954599731396648). I couldn't find a solution. I already know how to use ctx.message.author.id but I can't find a way to make that work with every discord user.
To get the tag you can use the following method
user = await bot.fetch_user(ID) # ID must be an int and this could be could be client for you, be careful as this pings the API and can be abused if not correctly limited.
# user.discriminator will return their tag.
You can check all attributes that user can have here
To get the tag, you first have to get the user object from the id using discord.utils.get:
user_id = #insert the id of the user which you want the tag of
user = await discord.utils.get(client.get_all_members(), id =user_id)#might by something like bot.get_all_members for you
tag = user.name

Show only one user that you follow

I use this package for follow management, but I'm having a hard time showing all posts from all users that are being followed.
https://github.com/overtrue/laravel-follow
In particular, the problem is that only posts from only ONE user are shown. So even that 10 users are being followed, it only shows one.
My code is this, I'll do something wrong in the query (first()), but putting get() generates error.
$items = Auth::user()->followings()->first()->items();

The most efficient way to access a user objects sub-object?

In my app I am using the parse framework. The basic breakdown for my current situation is that I have users who can like photo albums or photos individually. If a user likes an individual photo I want to place that photo into a new album specific to that user. That way I can easily retrieve an album filled with any given users liked photos.
I want the logic to be as simple and straight forward as possible and I have come to a conclusion, but I need another opinion to see if that's the best way to do it.
I plan to have a pointer to a 'liked photos' album as an object that is accessible on any user object. That way if a user likes a photo I can set the photoAlbumOwner as that album object on a users profile. Then for future retrieval I just need to find all photos that are associated with that album.
Every other option I have thought about requires me to fetch/search data to find the album for a specific user every time they like a photo. That would not be desirable because it's just extra data needing to be downloaded, which leads to more time.
Is this the best way to go about this or is there another option that would be more simple?
I would create an array field called likedPhotos in the _User class and then just add an reference to this liked photo.
Javascript code:
function likePhoto(photo) {
var user = Parse.User.current();
user.add('likedPhotos', photo);
user.save();
}

how to get the fan page name of Facebook wall post?

I am reading the wall posts of fan pages under my FB account using C# SDK. I would like to know the page id of the wall post. Is there any property in C# SDK?
As people start to use the Graph objects more an more, the FQL seems to be fading. But FQL is not deprecated (at least not yet).
For a particular wall post you're reading via your C# SDK, simply FQL it:
SELECT source_id FROM stream WHERE post_id = {post_id}
For more information https://developers.facebook.com/docs/reference/fql/stream/
For information on how to make an FQL query run in the C# SDK, see:
http://blog.prabir.me/post/Facebook-CSharp-SDK-Making-Requests.aspx
But it's going to look something like this
var client = new FacebookClient(access_token);
// this is where you already grab your post, so you have post_id
var data = client.query("SELECT source_id FROM stream WHERE post_id =" + post_id);

Displaying specific content to specific user in Joomla 1.5

To be short, It's a website for an investigations lab.
I need to display specific content (lab report) to specific user. Users will be given a username and a password when leaving and will be asked to login on the website to access his/her report with the credentials given to him.
So , it's a "specific content" for "specific user" - Moving to 1.6 is not an option.
I have a solution in mind but involve a lot of core hacking and will take some time ... If any one been in a similar situation or have an idea in mind I would appreciate your help.
Ok, this can be done but it's going to take a little trickery to get there. First, you are going to need a way to post the lab reports and associate them with a user. I would use K2 for this since you can add the report as an attachment to an item. You can also add extra fields to K2, which would be the next step. You'll need an extra field where you can enter a user ID number that you will use to determine if a user is allowed to view the content.
There are several steps you will need to take to now filter the content so only the associated user can see it.
You will need to get the user ID once the user is logged in:
$user =& JFactory::getUser();
$usr_id = $user->get('id');
You'll need a menu item that links to a K2 Category where all the lab reports go.
You'll need a subtemplate with a modified category_item.php for that category that only displays the associate reports:
if($this->item->extra_fields[USER_ID_EXTRA_FIELD_NAME]==$usr_id){
all the category item stuff
}
You'll need a subtemplate with a modified item.php for the category that again blocks users other than the associated user, basically the same code as #3 to either display the content or an error message.
The only other way I can think of that you can accomplish this would be to use an ACL component with a group for each user.
The K2 method with subtemplates would not require any core hacks and will work with a little work.
You can achieve what you want with Flexicontent http://www.flexicontent.org/ and Flexiaccess
Flexicontent is a K2 type component and I use them interchangeably. With Flexiaccess you can create items that are only available to certain users.
No hacks required.
Bad News: That cant be done with standard Joomla 1.5 (without hacking)
Good News: You can use one of the free or commercial Extensions for Joomla to accomplish that. I would suggest for example:
Admin-User-Access
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/9040
Or you can search for yourself:
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control

Resources