Twitter oembed for timelines? - php

Hi I use the following code to embed tweets but I am wondering if there is away as simple as the following to embed user profiles, I can't seem to find it on dev.twitter.com they keep taking me to make a widget. which is what I want to do but I want them to do it on request of the PHP
Currently i use something like this. But as you can see from below it only gets the status and not the timeline of the user.
$status = file_get_contents("https://api.twitter.com/1/statuses/oembed.json?url=".$links[$j]);
$stats = json_decode($status);
//$string = "https://api.twitter.com/1/statuses/oembed.json?url=".$links[$j];
if(isset($stats->errors))
{
}
else
$string=str_replace($links[$j],''.$links[$j].'',$string).$stats->html;
}

You can't get the html of users timeline, like you are getting it for status.
There is no end point with oembed available for users profile.
But you can easily build it yourself by following these steps.
Register an application
Get the API keys and access token
Use some library for PHP from these listed in this page Twitter Libraries, I would prefer going with the abraham's library
Get the user details by making request to this URL:
https://api.twitter.com/1.1/users/show.json?screen_name=[screen_name]
*Note: Twitter API v1 is deprecated so use API v1.1 for making requests
Fetch the JSON response and render it in your html code

Related

Scraping Facebook posts data using PHP Goutte?

I need to scrape post id, number of likes, number of comments, and username.
by using php code and I am currently using library Goutte.
How do I get post details? Is it possible using php goutte or do I have to use FB Graph API?
<?php
require 'vendor/autoload.php';//require the vendor/autoload.php file.
$client = new \Goutte\Client();//create a new client.
$crawler = $client->request('GET', 'https://www.facebook.com/username/');//go to site
You are forced to use the Facebook Graph API. Scraping users’ profile pages can give basic information about them, who they’re friends with, and what photos they’ve posted.
Facebook realise the potential harm to user privacy from allowing anyone to scrape profiles. For this reason, most elements of a typical Facebook profile are set to private, meaning that they can’t be viewed by anyone who that user hasn’t added as a friend. If you try to scrape a random person’s Facebook account, you may not be able to pull much information other than their name, their profile picture, and any old posts on their timeline which haven’t been made private. So, I advice you to use the Graph API, take a look to the docs from here. If you have any problem with the Graph API, post another question.

Custom Activity Feed for Facebook Page

Research and Reasoning
I haven't worked on a Facebook Application for a while, thus am a little rusty with how the Graph API works.
I have had a look at various topics and pages such as:
https://developers.facebook.com/docs/reference/plugins/activity/
How to Style Facebook Activity Feed
From what I can gather, getting the activity of a facebook page is pretty simple, however, before I proceed, there are a few things I would like to iron out before to ensure I build the app or write the script in the best possible way...
My Question
I would like to gather the status updates of a Facebook Like page and then feed this data to my News page on the website I am building.
My method would be a simple call to the Graph API to gather the data, and then display it on screen.
My question is, can I do this without creating a Facebook App, and therefore do I even need the PHP SDK?
Is it possible to achieve it like so and are there any request limits:
$url = 'https://graph.facebook.com/LIKE_PAGE_ID/feed';
$result = json_decode(file_get_contents($url));
If the above is the correct answer to this question then please let me know and I will close this question
Update
I have tried the above URL with my like page and it says that I need an Access Token. This is what I feared... Is it possible to get this data without being logged in, and without having set up a Facebook Application?
Why not create a Facebook app and use App Access Token to retrieve the feed for the Public pages.
Though you might get feed of some pages without app access token or response for different end points without access_token, but as the Facebook's API is constantly changing, and would finally settle with authorized request to their end points, I would suggest you to use the App Access Token which is can be created with the format
App_ID|App_Secret
So instead of your call for $url that you had you can change it to
$url = 'https://graph.facebook.com/LIKE_PAGE_ID/feed?access_token=App_ID|App_Secret';
Which you can then json_decode. Also there is nothing on binding to use PHP SDK, and in your case, it is not even required.

How to "GET" Facebook page statuses via Graph API for mobile website

I'm designing a mobile website for my church, and I would like to post my church's Facebook status updates on the website. I tried the Facebook like box, but I found it limited in functionality, and it doesn't work very well on a mobile website.
I then discovered Facebook's Graph API. I found a PHP script to use on my website (http://stackoverflow.com/questions/9373645/can-you-get-a-public-facebook-pages-feed-using-graph-api-without-asking-a-user), and I created an app on Facebook. Using Facebook's Graph API Express, I'm trying to customize the output so I ONLY obtain my page's status updates and timestamps.
For example, I tried https://graph.facebook.com/[profile ID]/posts. However, this includes when I posted pictures and created events; I only want status updates. Is there any way I can use Graph API to limit the posts by specifying the "type" as "status"? I can't get it to work.
Ideally, I want the code to get my church Facebook page's status updates, particularly the "message" and "created_time" fields, and I would like to limit the results to 10.
If there is a better way to do this, please let me know. I am a novice at this, and I'm basically just trying to find the code to make this happen.
Is there any way I can use Graph API to limit the posts by specifying the "type" as "status"?
The Graph API includes a "statuses" endpoint as part of the User object. It is accessed in a similar fashion as the "posts" endpoint:
https://graph.facebook.com/[profile ID]/statuses
To limit the results to only 10 statuses, you could add a "limit" parameter to the URL:
https://graph.facebook.com/[profile ID]/statuses?limit=10
For example, the page for Boo facebook.com/boo using an application access token.
<?php
$access_token = '1111111111|2Cha_1-n5';
$graph_url = "https://graph.facebook.com/Boo/statuses?limit=10&access_token="
. $access_token;
$page_posts = json_decode(file_get_contents($graph_url), true);
foreach($page_posts['data'] as $post){
$message = $post['message'];
$post_time = $post['created_time'];
}
echo $message .' '. $post_time;
?>
More information on this and other ways to filter the API's output can be found in the Graph API's Pagination documentation.

Easy way to get facebook statuses from a particular page in PHP?

I need to grab the statuses from a Facebook page via PHP to display on the page. I don't want to have people logging in to facebook just for my script to grab the statuses from the page since it is a public page and isn't restricted. I have the Facebook API for PHP in my projects directory but have no idea how to use it to do what I want it to. Could someone give me a code example of how I'd do this? Thanks!
It's really a straight forward task if you follow the documentation. Since /PAGE_ID/feed requires any valid access_token, your app access_token is enough to get the data:
Open the Graph API Explorer (I'm querying coca-cola/feed)
Get an app access_token from the Access Token Tool and use it instead of yours
You're done!

PHP class or library to allow tweeting from a website

I know there are quite a few libraries out there that that allow Twitter to be integrated into a website. But I haven't yet found what I am looking for (or maybe my understanding of twitter API is lacking). I want to be able to tweet events that occur on my website - BUT in addition, I want to be able to add tweeted from www.example.
For instance, when I send tweets from my blackberry or iphone (or indeed from some other sites), underneath the tweet, there is a message that says, tweeted from (for example blackberry). Does anyone know of a PHP library or class that allows me to send tweets but also with a kind of 'signature' that says where the tweet was sent from?
Edit
Additionally, I want users to be able to tweet from my website. When they tweet, I would like the tweet to say that where it came from (for example, like it does for blackberry phones etc, as I described above).
It is not clear to me whether I still need a PHP application for this requirement, and also how to implement it. Do I need an additional library for allowing users to tweet from my website?
Note: my users do not log into my website using a twitter login, so my website does not have access to a users Twitter username/password etc.
First you must register an app at http://twitter.com/apps, then you can use this twitter class -> http://classes.verkoyen.eu/twitter_oauth
I wrote a tutorial on how to do this http://blog.cmstutorials.org/reviews/general/how-to-update-your-twitter-status-using-php , just follow the steps and you should be good to go
edit: how to include a link
you can write function to get a shortened url because you only have 140 charachters
you can then use this function:
function getBitlyUrl($url)
{
$bitlylogin = 'your login name';
$bitlyapikey= 'your api key';
$bitlyurl = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitlylogin."&apiKey=".$bitlyapikey);
$bitlycontent = json_decode($bitlyurl,true);
$bitlyerror = $bitlycontent["errorCode"];
if ($bitlyerror == 0) {
$bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
}
else $bitlyurl = "error";
return $bitlyurl;
}
then just call it like this:
$url = getBitlyUrl('yourlink');
you can then just add $url to your tweet
You need to create an application in twitter. And tweet via that application (using API) on twitter. the 'via XYZ' will be automatically added.
http://www.twitter.com/apps
You need to register an application at http://dev.twitter.com
(There you can also set information for "tweeted by" or your page url)
Afterwards you can use a library from the list here:
http://dev.twitter.com/pages/libraries#php
like https://github.com/abraham/twitteroauth or https://github.com/basilbthoppil/oauth_twitter
(It has to support the oauth authentication system I think some of the librarys on the twitter page are outdated)
When you create an instance of the library in your php script you have to pass your authentication tokens to the constructor (how you do this varies from library to library so just read the docs).
Any tweet posted by using the library will contain your "tweeted by" etc. information.

Categories