Facebook API photo uploading with imagepng - php

I have a quiz application on Facebook. It uploads a photo to user's photos at the end of the quiz.
$photo_upload = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . './images/userimg.png',
'message' => $message,
)
);
But it is a sample image, the same for everyone. I want to make it personal by writing the user's name on the image. Part of create-img.php:
try {
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
error_log($e);
$user_id = null; }
$username = iconv("UTF-8", "ISO-8859-2", $user_profile['name']);
$text = iconv("ISO-8859-2", "UTF-8", "Hello ". $username);
...
header('Content-type: image/png') ;
ImagePNG($image) ;
ImageDestroy($image) ;
imagepng($image, "./images/imgs_to_post/sample_userimg.png");
exit ;
It can be included in HTML, works fine, the image shows up with the user's name.
<img src="create-img.php" alt="" />
But when I try to put create-img.php as source in the API call above, i get an error.
Fatal error: Uncaught OAuthException: (#1) An unknown error occurred thrown in /home/mmdesign/public_html/.../php-sdk/base_facebook.php on line 1128
How can I put the result image of imagepng in the API call as source?
Thank you in advance.

But when I try to put create-img.php as source in the API call above, i get an error.
Of course, because that file contains PHP code, not image data. (If you think the PHP code is parsed at this point, you’re wrong.)
Write the image to HDD first, and then feed the API the path to that image.

Related

Downloading image to webdav folder from url with new name and retrieve

Hi I have this PHP code (Custom Script) to query for FileAttachment URL from RightNow Incidents,
<?php
define("CUSTOM_SCRIPT", true);
define(DEBUG, false);
define(COMMIT, true);
ini_set('display_errors',1);
error_reporting(E_ALL ^ E_NOTICE);
$ip_dbreq = true;
require_once( get_cfg_var("doc_root")."/ConnectPHP/Connect_init.php" );
use RightNow\Connect\v1_2 as RNCPHP;
try{
initConnectAPI('user','Pass');
}
catch(Exception $error) {
echo $error->getMessage();
}
$img_url = "";
$inc_id = 296;
$entity = RNCPHP\Incident::fetch($inc_id);
foreach($entity->FileAttachments as $fileattach) {
$img_url = $fileattach->getAdminURL();
}
$img_id = 23;
$image_location = HTMLROOT . "/euf/assets/images/integration_images/images/".$inc_id."-".$img_id.".png";
file_put_contents($img_url, fopen( $image_location , 'r'));
header('Location: $image_location');
?>
This will return the file downloading url which if opened in browser will automatically download the image to my computer
URL : https://host.com/cgi-bin/some.cfg/php/admin/console_util/fa_get.php?p_parms=eUofFOziR6q7tVDrMAkPfz_F0iz5Nf17TjtEH18Z72PdbM9JJq6g4VNUF4oXfPY~UpgHsJhH0Nr7KKYBg78sV69A2pcj3h1cn5_mRTSyJtQHtkwQz8bqcldb8gjEUwtfQkgPVNx3u1jHjCESYm7aXKv7v4zqVV1_f_MTJp1ooey9tMHBsFlsKw0jQjurEl15gIeFNt011UglH3ccOhCvgimvVmsMvs2HbrVymNwZ1HmMtKewDQfdCy35Oi5kgotrQHoJ3QQn10fuGTjlrjgW1MEXncdTUHx2645YZxlmraur7_mpIJzWw9Rg!!
I want to use this url to download the image directly to Customer Portal folder
"/euf/assets/images/" with incident ID and Image ID as name, then build a new url for that image and redirect my above script to that image url so that we can see the image on browser directly.
Send the content type header before the location header so that the browser knows the endpoint is an image.
This approach is dangerous, though, because you are basically exposing protected incident data on the public internet as assets is not a secured folder.

Upload Files to Sharepoint Library through WS with PHP (NTLM & ThyBag)

I use the Lists-WS from Sharepoint to retrieve information about DocumentLibraries and the files in these Libraries. Now I want to upload new files. How do I implement uploads with PHP? Till now I use Thybag SharePointAPI to get information (Link).
(the SharepointServer uses NTLM-Authentication)
THX in advance!!
UPDATE:
I want to call the Copy.asmx WS from sharepoint. To do so, I use the following lines:
$sourceurl = 'http://null';
$params = '
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>'.$sourceurl.'</SourceUrl>
<DestinationUrls>' . $destinationURLs . '</DestinationUrls>
<Stream>' . $stream . '</Stream>
</CopyIntoItems>
';
$xmlvar = new \SoapVar($params, XSD_ANYXML);
// Attempt to run operation
try {
$result = $this->soapClient->CopyIntoItems($xmlvar)->CopyIntoItemsResponse->CopyIntoItemsResult;
} catch (\SoapFault $fault) {
$this->onError($fault);
}
But I dont even get any response ($result == NULL).....
You can use SPServices' CopyIntoItems method. You can find a detailed conversation here containing the details on using the CopyIntoItems service to upload a document.

Error: Server error: couldn't open file "Capture.png"

I want to post an image on twitter but I can't. I am able to post only text message with twitter API.
The error is: Error: Server error: couldn't open file "Capture.png"
I use wamp server. The picture is in the same folder with the script.
Where is the problem?
require_once '../src/twitter.class.php';
// ENTER HERE YOUR CREDENTIALS (see readme.txt)
$twitter = new Twitter. ('raQBedybFLb', 'HWgN6Qt11jg0LY', '862846056-ndeGfMA83r9ldh', 'VMBvHDahXnGp');
$p='./Capture.png';
try {
$tweet = $twitter->send('testing twitter api', $p); // you can add $imagePath as second argument
} catch (TwitterException $e) {
echo 'Error: ' . $e->getMessage();
}
You may use $p = realpath('Capture.png');

CurlException failed creating formpost data

i'm trying make photo upload, but i'm not getting, well the goal was publish in my fan page wall, i cann't, so i decided to test in my wall "me/photo", same thing, this error appears!
CurlException failed creating formpost data
this is my code, and the page "config.php" contains only configurations, appid, secret, etc...
anyway, What am i do wrong?
$photo = '/imagens/teste.jpg'; // Path to the photo on the local filesystem
$message = 'Photo upload via the PHP SDK!';
?>
<html>
<head></head>
<body>
<?php
if($idUsuario) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'access_token'=> $facebook->getAccessToken(),
'source' => '#'.$photo,
'message' => $message
)
);
echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
echo '<br />logout';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo 'Please login.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo 'Please login.';
}
?>
</body>
</html>
You can see that this code is the same code example in dvelopers.facebook to make upload!
You must send the realpath to the API.
Change:
$photo = '/imagens/teste.jpg';
By:
$photo = realpath('/imagens/teste.jpg');
And check if your path is good.

How to specify ALBUM NAME + DESCRIPTION on photo upload, and NOT base it on APP name? (Facebook Timeline)

I use this script here for my Facebook App.
It uploads a photo on a user's Facebook profile, and creates a new album for that photo.
The script returns "[APP NAME] Photos" as the Album name / title (without quotations).
- [APP NAME] being the name of my Facebook APP -
Basically, I don't want that Album title. I want to specify an Album title on the script.
What I want is :
... to be able to specify the Album's name / title to create, from the script.
And if possible, specify Album description too.
This is the script -
$root_url = "http://www.WEBSITE.COM/";
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
// Get image from URL
$img = $_GET['i'];
// Change location depending on which type of cover
if($get_set != 1) {
$photo = './PATH/'.$img.''; // Path to the photo on the local filesystem
} else {
$photo = './PATH/'.$img.'';
}
$message = 'THIS IS THE PHOTO CAPTION';
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . $photo,
'message' => $message,
)
);
// echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
print "<script>window.location = '".$root_url."index.php?cover=uploaded'</script>";
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo '<script> window.location = "' . $login_url . '"; </script>';
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br />logout';
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo '<script> window.location = "' . $login_url . '"; </script>';
//echo 'Please login to continue.';
}
Seeing this one here, I am confident that is possible.
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
I just don't know how to work it in there...
Looking forward to solutions. Thanks for your time!
As it says in the documentation of the Photo object:
you can upload a photo by issuing an HTTP POST request with the photo
content and an optional description to one these to Graph API
connections:
https://graph.facebook.com/USER_ID/photos - The photo will be published to an album created for your app. We automatically create an
album for your app if it does not already exist. All photos uploaded
this way will then be added to this same album.
https://graph.facebook.com/ALBUM_ID/photos - The photo will be published to a specific, existing photo album, represented by the
ALBUM_ID. Regular albums have a size limit of 200 photos. Default
application albums have a size limit of 1000 photos.
You are currently using the first option, using the 2nd one requires for you to have an album id, which you first need to create:
You can create an album for a user by issuing an HTTP POST request to
PROFILE_ID/albums with the publish_stream permissions and the
following parameters
(Albums connection of the User object)
The problem is that you'll have to save this album id for the user to use in the future when the app needs to upload again to the album.

Categories