how to allow users of a website to email their contacts? - email

I just would like some guidance as to where to start this project. If I want to enable users of my website, to email all their contacts about an update (similar to linkedin does when you join) how should I go about doing this? I honestly have no idea where to begin.

I'd start by looking at OAuth - the user allowing your service access of some form to their account. You can start with Google's API info here:
https://developers.google.com/accounts/docs/OAuth2

I don't know what programming language you are writing this in so heres some pseudocode.
foreach contacts in databaseresults{
$To = '"' . $databaseresults['first_name'] . '" <' . $databaseresults['email'] . '>';
$Headers = "From: \" Some Company \" <support#reallycooldomain.com>"."\r\n".
"Content-type: multipart/mixed; boundary=$someMD5Hash"."\r\n";
$Message = "--$someMD5Hash\r\nContent-Type: text/html;" . "\r\n" . $someHTMLContent . "\r\n\r\n" . "--$someMD5Hash--";
$subject = "A Squirrel Added a Nut to your pile!";
mail($To,$Subject,$Message,$Headers);
}
At least thats some PHP to work

Related

Facebook page tab app session across subpages PHP SDK 4

See the full original question further down
Using the latest Facebook PHP SDK 4.4.0, in my main app page I can do the following to get a user id etc.
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// **depcrecated** get like status - use for likegates
echo '<p>You have '. ( $pageHelper->isLiked() ? 'LIKED' : 'NOT liked' ) . ' this page</p>';
// get admin status
echo '<p>You are '. ( $pageHelper->isAdmin() ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';
?>
This does not work on sub pages of my app ... Why is the session (and amongst other things, the signed request) lost? How can I get them back and how can I get methods such as getUserId() from the the FacebookPageTabHelper to continue to work on sub pages?
full original question
I'm fairly new to Facebook app development and I'm having problems with session management and I just can't seem to be able to wrap my head around it. Of course it doesn't help that the official documentation is almost useless.
My problem is that the page session get lost when moving away from the apps main page to a subpage within the Facebook page tab app iframe.
I use the following PHP code to obtain the session and user id on the main (initial) app page and it works great:
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
?>
But it doesn't work on sub pages :( when a user clicks on a menu item (or any other link inside the app/iframe), the session goes bye bye. Which is not ideal as I need the user id of the user to track whether or not that user has completed certain actions. Of course I could send the ID along with every request, but there must be a way to have a persisting session, no?
Is there a way to retrieve the session on a sub page in PHP? If so, how? Or do I have to load additional content using javascript? And how would that work, if I can't keep the session between requests and therefore have no way of identifying which user a request came from? How do others handle this?
What I'd like to avoid is to write my own user session management, which would solve the problem but is simply not in the budget and I was hoping I could work with what Facebook already had on offer. Especially since my app doesn't require user information/permissions of any kind.
Thanks a lot in advance for any info on this topic, greatly appreciated, going in circles here.
Edit to clarify: I thought of just saving the Facebook session in a PHP session cookie, but how would I use that to reconnect with Facebook after changing the page?
I finally managed to solve this problem. I'm not sure whether this is considered the right way or can even be a recommended way of doing this, but it works and since time is of the essence, I don't have much of a choice.
If anybody has any further ideas or suggestions, please comment.
Here's how I did it:
// store the signed request
if(isset($_REQUEST['signed_request'])) {
$_SESSION['signed_request'] = $_REQUEST['signed_request'];
} elseif($_SESSION['signed_request']) {
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signed_request'];
}
// assign the stored signed request to REQUEST, GET and POST vars (the unsavory bit, imo)
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signedRequest'];
FacebookSession::setDefaultApplication(APP_ID, APP_SECRET);
$accessToken = APP_ID . '|' . APP_SECRET;
$this->session = new FacebookSession($accessToken);
$pageHelper = new FacebookPageTabHelper();
$isAdmin = ($this->pageHelper->getPageData('admin')) ? $this->pageHelper->getPageData('admin') : 0;
// get pade id
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// get admin status
echo '<p>You are '. ( $isAdmin ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';

Grab Bing Result From Search Pages

I want to get the bing result without api , I want to get them direct from bing pages using php. I don't know how to do it.
you can use http requests and pares the results to get what you want
you can use regular expressions
example:
$results = file_get_contents("http://www.bing.com/search?q=regular+expressions");
you will find the all HTML content of the page, like you see when click on "view page source"
then apply regex on it to extract the results
Check out this script: http://www.fromzerotoseo.com/scraping-bing-serp/
in particular the regular expression search which grabs the links:
preg_match_all(
'(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU',
$result['EXE'], $matches);
Just use simple_html_dom and do a simple parse. To get # of bing results, you have to find a specific class called "sb_count". If you need links, change the class by "b_attribution" to get all the links.
You can execute your query as follow by looping through the result page using foreach:
include_once 'simple_html_dom.php';
header('Content-Type: text/html; charset=ISO-8859-2');
$html = new simple_html_dom();
$param = 'Your query';
$html -> load_file('https://www.bing.com/search?q=' . $param . '&go=Submit&qs=n&form=QBLH&pq=' . $param . '&sc=8-6&sp=-1&sk=&ghc=1&cvid=e3777d60b1f04c90a3d8f08903433c7a');
foreach ( $html->find('.sb_count') as $post){
echo '<p>' . $post . '</p>';
}

Migrate this Zend Gdata code from ZF to ZF2

Sorry for such a bad question but I spend 2 hours without any success. Zend Docs are horrible ...
I have found this Zend_Gdata library and Picasa data API -- loader.php file missing, but its crashing at line 2 Class 'Application\Controller\Zend\Loader\StandardAutoloader' not found, which obviously isn't the correct path.
I am not sure why ZF does not use
...\vendor\ZF2\library\Zend\Loader\
Im using https://github.com/zendframework/ZendSkeletonApplication which is working, but nothing else works out of box with zf2 and all help topics are described incompletely. A mess in my eyes ...
However here is the code.
//Change this for your domain
$domain = 'yourdomain.com';
$email = 'ad...#yourdomain.com';
$passwd = 'p#ssword';
$user = 'jsmith';
$newuserpassword = 'secretp#assword';
//Connect as admin to Google Apps
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, Zend_Gdata_Gapps::AUTH_SERVICE_NAME);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
$gdata = new Zend_Gdata_Gapps($client, $domain);
//Now change the user's password
$updateUser = $gdata->retrieveUser($user);
$updateUser->login->password = $newuserpassword;
$updateUser = $updateUser->save();
There's a new API that you can use even if Zend 1 or 2:
https://github.com/google/google-api-php-client
Here's the page with installation instructions and a getting started:
https://developers.google.com/api-client-library/php/
And here are the available services:
https://github.com/google/google-api-php-client/tree/master/src/Google/Service
Hope it help.
There's no such thing as Zend_Loader in zf2 and the code you have posted is for zf1. If you have the barebones application working, then you will already have the autoloader working correctly (I presume you're using MVC and this code is to go in a controller, not a single file).
If you have the autoloader setup correctly, you also don't need to use Zend_Loader::loadClass.. as they will be autoloaded.
As for Gdata in zf2 - you will need to get the package, which can be found here https://packages.zendframework.com/. Good instructions are here: Zend Framework 2.0.2 YouTube API
Converting the code from zf1 to zf2 should be pretty easy.
However, unfortunately the gdata package is no longer maintained, so you are advised to use https://code.google.com/p/google-api-php-client/

How do I echo something from Facebook's graph api?

I want to display the content from: https://graph.facebook.com/comments/?ids=http://lujanventas.com/test.php in my site.
How can I do it aside from an AJAX call? Can it be done without JS?
you can create a server side script that reads the content of the file and echos it
this is an example for such script in php:
$ids = "http://lujanventas.com/test.php";
$url = "https://graph.facebook.com/comments/?ids=".urlencode($ids);
$data = json_decode(file_get_contents($url),true);
foreach($data[$ids]["comments"]["data"] as $comment){
echo $comment["message"]."<br /><br />";
}

sphotos.xx.fbcdn.net Issue With Full Size Profile Pictures

I'm stuck with what is causing this issue. If i'm logged in as my account, the code below does not show user: 100000920350966 but if i logout & back into my wife's account I can now see that users profile picture.
Error I get logged into my FB account:
http://sphotos.xx.fbcdn.net/hphotos-snc6/230962_10150332269178009_784368008_9751025_7802946_n.jpg
An example of one that does work:
http://a4.sphotos.ak.fbcdn.net/hphotos-ak-ash4/419763_10151360491990078_877370077_23594484_2739927_n.jpg
the code I am using is the PHP SDK and this piece for getting an image:
function randomUser() {
$query = mysql_query("SELECT the_facebook_id FROM users WHERE the_facebook_id != '$facebook_id' ORDER BY RAND() LIMIT 0,1");
$result = mysql_fetch_array($query);
mysql_close();
return $result; }
$theuser = randomuser();
$albums = $facebook->api('/' . $theuser[0] . '/albums');
foreach($albums['data'] as $album){
if ($album['type'] == 'profile'){
$photos = $facebook->api('/' . $album['id'] . '/photos');
$random_pic = $photos['data'][0]['source'];
}
}
echo "<br /><br />The User: " . $theuser[0] . "<br />";
echo "Photo Source: " . $photos['data'][0]['source'] . "<br />";
echo "THE PHOTO HEIGHT: " . $photos['data'][0]['height'] . "<br />";
echo "THE PHOTO WIDTH: " . $photos['data'][0]['width'] . "<br />";
I honestly have no idea what when in my account I can't see particular profile pictures but in my wife's I can see all of them. All help is greatly appreciated!
Cheers
Interesting case you've got there.
I can't tell you what's wrong, but I have a guess which is divided to two options.
The urls in question are for static content and so the content is not depended on the current user.
However, that url is of a cdn, which means that the copy of the content you get is different (probably) from the copy I get, which explains how is it that you're getting an error while I'm able see the picture for the same url.
The two options:
The cdn you are directed to is not available at all and so all images you ask from it will result in page not found error. Try to ping sphotos.xx.fbcdn.net and see what you get.
The cdn you are directed to does not have a copy of the image you are trying to get, maybe for some reason an error occurred when the file was supposed to propagate to the server.
This is just a guess of course, in any case I recommend you to file a bug report and have the facebook team look it up, it might take some time for them to check it out/do something about it though.