if (isset($_GET['data'])) {
    $new_image_name = md5(time() . 't' . $fb->id) . '.png';
} else {
    $new_image_name = md5(time() . 't') . '.png';
}
imagepng($profile_image, $new_image_name);
$localFileName = __DIR__ . '/' . $new_image_name;
$remoteFileName = $new_image_name;
$handle = fopen($localFileName, 'r');
$container->uploadObject($remoteFileName, $handle);
$base_url = 'http://tomatoeyes.com?i=';
$permalink = 'http://9ac6f2b05dad964c4500-289fb48c1e3607de5437a0c9e6e868be.r38.cf2.rackcdn.com/' . $remoteFileName;
//header('Content-type: text/plain');
header('Content-type: application/json');
$results_link = bitly_v3_shorten($base_url . $permalink, 'c0556ee357cfdf6c030ea09d966dab6388eae68b', 'j.mp');
$short_image_url = bitly_v3_shorten($permalink, 'c0556ee357cfdf6c030ea09d966dab6388eae68b', 'j.mp');
$short_image_url = $short_image_url['url'];
$share_url = $results_link['url'];
imagedestroy($profile_image);
if (count($json->photos[0]->tags) == 0) {
    $results_array = array('error' => 'no tags', 'image' => $permalink, 'share_url' => $share_url, 'short_image_url' => $short_image_url);
} else {
    $results_array = array('image' => $permalink, 'share_url' => $share_url, 'short_image_url' => $short_image_url);
}
$results_array = json_encode($results_array);
echo $results_array;
unlink($localFileName);
//DRUPAL UPLOADING
if (isset($_GET['data'])) {
    $request_url = 'http://shoofly.me/api/user/login.json';
    // User data
 private function finishPublishToFacebook()
 {
     // See if we can get a picture of the other introducee
     if ($this->other->getLinkedInId() != null) {
         $picture = $this->other->getLinkedInPicture();
     }
     if (!isset($picture) && $this->other->getTwitterId() != null) {
         $picture = $this->other->getTwitterPicture();
     }
     if (!isset($picture) && $this->other->getFacebookId() != null) {
         // Shorten the picture URL with BITLY so we can publish it on Facebook
         $results = bitly_v3_shorten('https://graph.facebook.com/' . $this->other->getFacebookId() . '/picture?type=normal', 'j.mp');
         if (!empty($results['url'])) {
             $picture = $results['url'];
         }
     }
     try {
         $params = array('description' => ' ', 'caption' => str_replace('INTRODUCEE_NAME', $this->other->getName(), str_replace('INTRODUCER_NAME', $this->userName, Content::c()->introduce->notification)), 'link' => $this->introductionUrl, 'name' => $this->other->getName(), 'access_token' => $this->userDetails['facebook_access_token']);
         if (!empty($picture)) {
             $params['picture'] = $picture;
         }
         $statusUpdate = SessionManager::getInstance()->getFacebook()->api('/' . $this->introducee->getFacebookId() . '/feed', 'POST', $params);
     } catch (FacebookApiException $e) {
         // Could not post to Facebook.
         Debug::l('Error posting to Facebook ' . $e);
         return false;
     }
     return true;
 }