I was wondering if it was possible to use PHP / AJAX to have a string of text sharable to Facebook? For example, I use PHP to return an SQL query, then use that same string of text in correspondence with a button, to share to my Facebook wall. So, it might look something like this in the PHP:
while($note_row = mysql_fetch_row($result)) {
echo '<p> "' . $note_row['my_note_text'] . ' "</p>';
echo '<input type="button" id="' . $note_row['my_note_id'] . '" class="share-to-facebook" value="share" />';
}
If anyone has some advice whether this is possible I'd be super happy. I also apologise if my PHP is wrong, I haven't checked it.
You have some options:
sharer.php
https://www.facebook.com/note.php?note_id=407822831963
Create a share link. You can set title and url.
Feed Dialog
https://developers.facebook.com/docs/reference/dialogs/feed/
Creates a share dialog. More options for description and image etc. Might be a replacement for sharer.php.
If you need to post to the wall from your app, you need the get permissions by having the user accept your app to Facebook. Read more about authentication at https://developers.facebook.com/docs/authentication/
Related
I asked the same question earlier and it got down voted and I have no idea why. I'm building a class that outputs a news feed, but it's a very structured html that I'm going to use a lot on the site (hundreds of times), so I'm using a class method to display the feed html and everything. And I just echo the whole thing.
The method is set up this way:
private function feed ($var)
{
$Statement = $this->Database->prepare("SELECT * FROM feed WHERE col = ? ORDER BY timestamp DESC LIMIT 50");
$Statement->execute(array($var));
while ($row = $Statement->fetch(PDO::FETCH_ASSOC))
{
echo ' <div class="feed-box">
' . /*facebook name retrieved from the facebook */ . '
' . $row["post"] . '
<br/>
</div>';
}
} //end feed
The class is set up so that another method that has more of the html template calls this feed method. (I'm not trying to be too redundant here, but again the last time I asked this question it got down voted). So I'm pretty new to oop, and I'm looking to display the profile pictures of people who are logged in with facebook. This isn't necessarily a facebook question because I know how to do it normally, but I don't know how to get the facebook information within the class scope using just their id. Normally I;d get their picture by going linking to this url https://graph.facebook.com//picture. How do I do this within the class when I only sotre their facebook id in the database? I've been working on this problem for a couple days now, and I can't figure it out on my own. So I really appreciate your help.
It's getting to the point where I just want to statically type everything out because I know I could easily do that, but I'd really love to learn what the proper way is, especially since editing so many of these little boxes if I want to change something one day would be a real hassle. Thanks for your help. I really appreciate it. Let me know if anything is unclear I'll update the questino as soon as I can.
How do I do this within the class when I only sotre their facebook id in the database
echo '<img src="https://graph.facebook.com/' . $row['facebook_id'] . '/picture" />' ;
You say you only store the facebook id in your database. That is all you need to display the picture. Just append /picture to the user's FB graph link to get the picture.
Been at this for a while and cant figure it out so i thought id come to the ppl who know.
my php / sql is so-so but.....this is what im trying to do / figure out..
i have a database setup to take in messages (of any sort) and works fine. The user enters data in a field, hits send, and the message gets logged.
But when a user puts in a link for example " http://www.google.com "
its stored in the DB just fine but when its printed back onto the page, it comes back as plain
text, what i want is that when the page throws back the message with the link in it, that the link is live and clickable.
Ive googled my a$# off but im guessing im searching for the wrong thing (or im missing something unbeknownst to me. )
Any tips/*direction* etc, ill gladly accept. also, I dont mind doing the work/research so if you have links only ill take those too.
Thanks in advanced.
You need to parse messages plain text in order to find links. Then, change link texts by adding an anchor tag (<a>).
This link should help you.
you need regular expressions to detect links and convert them to ...
see the answer here:
PHP validation/regex for URL
<?php echo "your_field"; ?>
Something like this should work (I took this from some code I wrote for a client):
$query = mysql_query("SELECT * FROM wcordersinfo WHERE dealer_id = '" . $dealer_id . "' && drawing_num = " . $_GET['reference_id'] . "");
while ($orders = mysql_fetch_array($query)) {
if ($orders['drawing_num'] != '') {
$link_open = '<a href="http://www.example.com/dealers/order-details.php?reference_id=' . $orders['drawing_num'] . '">';
$link_close = '</a>';
} else {
$link_open = $link_close = '';
}
and then where you want to display the content:
<?php echo "<li>' . $link_start . $orders['carrier'] . $link_end . '</li>"; ?>
You may want to check out http://www.php.net/manual/en/function.preg-replace.php for replacing regular expressions with something.
There you want to replace every website with a typical html link syntax like ...
I would like show the "select friends" dialog before publish to a friend wall, like that:
I am not sure if it is possible with the PHP SDK, I didn't find anything about it on the Fb documentation.
Could I also use a kind of Facebook URL, such as :
$link=https://www.facebook.com/dialog/feed?app_id=<your appid>&redirect_uri=<your redirecting link>&link=<link u are posting>&message=<message>.&picture=<picture URL you want to show>&caption=<title>&description=<description>&name=<title>
(this on is use to post to our own wall)
UPDATE:
After I have selected the selected friends uids, I want add them to the Graph API link and then publish to their wall.
if (isset($_GET['request_ids'])) {
$i = 0;
$n = count(request_ids);
while($n!=$i){
$link = ($link + "&to=" + $request_ids[$i]);
$i = $i +1;
}
echo "<script language=javascript>parent.location=''</script>";
}
Is something wrong with my php code?
Any help would be appreciated. Thank you.
Here it is the doc:
https://developers.facebook.com/docs/reference/dialogs/
https://developers.facebook.com/docs/reference/dialogs/requests/
You can either do that by using the JavaScript SDK, or the Graph API.
To use the graph api, you can build an URL like this:
https://www.facebook.com/dialog/apprequests
?app_id=<your-app-id>
&redirect_uri=http://www.example.com/response/
&message=Your%20message%20here
&display=popup
By specifying different values for "display", you can choose how to display the selector. Can be page, popup, iframe, touch, or wap.
When the user clicks the "send request" button, gets redirected to "redirect_uri" with shome get appended (I wasn't able to find the exact name for the get parameter, but it would be easy to find out).
UPDATE:
After the user clicks on "Send request", he gets redirected to:
<redirect_uri>?request_ids[0]=XXXX&request_ids[1]=YYYY&request_ids[2]=ZZZZ#_=_
So, in PHP, you'll find a list of ids of selected friends in $_GET['request_ids']. You can use that list to publish something on friends wall, by using the Graph API.
Side note: must have the same domain you specified as your site URL in the app configuration page.
UPDATE:
An improvement to your PHP code:
if (isset($_GET['request_ids'])) {
for ($i=0; $i<count(request_ids); $i++){
$link = ($link + "&to=" + $request_ids[$i]);
}
echo "<script language=javascript>parent.location=''</script>";
}
Then, what's inside $link?
To publish on one's wall, you should use the appropriate Graph API request, directly from the script you specified in redirect_uri.
Is there any way to share link of specific website through my twitter account with PHP? Instead of going to that website and clicking share and authenticating and posting, can i do all this with PHP? If yes, how? Meanwhile, I've managed to get the desired format for posting:
$tweeter_link = "https://twitter.com/share?original_referer=" . $link . "&related=&source=tweetbutton&text=" . $title . "&url=" . $link . "&via=SomeThing";
But I can't process it properly with curl.
I'm trying to issue a Facebook Graphp API search call for groups with a specific search term. The important fact is to search for groups not only beginning with the term but also to search for the term within the group name. So something like that.
FQL => SELECT * FROM groups WHERE groupname LIKE '%term%'
As far as i know this isn't possible in FQL. Therefore I have to use the Graph API search.
http://developers.facebook.com/docs/api#search
But I have to issue th call even if the user isn't logged in. Is this possible
or is there a possibility to log in a default user with some curl calls without user interaction (without displaying a form)?
If there is a simplier solution (for instance with FQL) please tell me.
I work with the graph API and not with the FQL so I'm not 100% sure on the differences etc etc... however a way I'd try is using the cURL script at http://developers.facebook.com/docs/authentication/#authenticating-users-in-a-web-application to get an auth token, then you must add the received auth token to the graph parameters as you can see on the site (a good way to test in the graph api is to click on the example likes or queries given while logged into facebook then copying the api code and breaking up the process like that [testing that you can get results you want from the query, testing that you can get your auth token then combining] so that you know what parts are 'problem' parts).
If that fails, scroll down to the "single sign-on with java-script" and have a look at the code they use to get the auth token from the facebook cookie, I notced you may be able to access that cookie from FQL.
I hope this was of some help! Please tell me if those ideas didn't work.
Jon
Using PHP-SDK 3.1.1, no auth or access_token needed. This sample assumes you have PHP-SDK installed on the page.
Use a form post the question to the page, arguments for get and post
are included. This will return the array from search https://graph.facebook.com/search?q=facebook&type=group
<?php
$q = urlencode($_GET['qs']);
if(!$_GET['qs']){
$q = urlencode($_POST['qs']);
if(!$_POST['qs']){
$q = "facebook";
}
}
$MEsearch = $facebook->api('/search?q='.$q.'&type=group');
foreach ($MEsearch as $key=>$value) {
$i=1;
foreach ($value as $fkey=>$fvalue) {
$i++;
if($fvalue[id]=="h"){
}else{
$groupname = $fvalue[name];
$groupid = $fvalue[id];
$groupversion = $fvalue[version];
echo $groupname. '<br />';
echo $groupid. '<br />';
echo $groupversion. '<br /><hr />';
}
};
};
?>
Sample Usage http://shawnsspace.com/plugins/photofeed.php Click Get Plugin at the bottom and use the search box to see this sample in action.