posting images into users feed with source is not working - facebook

i am trying to create a fb app using the user profile pic. app will generate a new image that image should post to user feed. I am trying to use "source" but it is not working. This is not giving full image. It gives thumbnails instead of posting full image. Here is my code
$canvas = imagecreatetruecolor($crop_width,$crop_height);
imagecopy($canvas,$currentimage,0,0,0,0,$crop_width,$crop_height);
$test = $data['user_id'].'test.jpg';
imagejpeg($canvas, $test,100);
$new = imagecreatetruecolor(150,150);
imagecopyresized($new,$canvas,0,0,0,0,150,150,$w,$crop_height);
$resize1 = $data['user_id'].'resize1.jpg';
imagejpeg($new, $resize1 ,100);
$source1 = 'black.jpg';
$background = imagecreatefromjpeg($source1);
$resize = imagecreatefromjpeg($resize1);
imagecopy($background,$resize,100,250,0,0,150,150);
$output = $data['user_id'].'output.jpg';
imagejpeg($background,$output,100);
echo '<div align="center"><img src="'.$output.'"></div>';
unlink($test);
unlink($resize1);
$access_token = "ABCDEFGHIJKLM";
$graph_url ="https://graph.facebook.com/me/feed?access_token=".$access_token."&method=post&source=http://www.Google.es/images/srpr/nav_logo39.png&message=logo";
$user_permissions = json_decode(file_get_contents($graph_url));
print_r($user_permissions);
Please help me this solves me to create a perfect fb app.

Related

How can i save the facebook profile picture to my local folder using facebook graph api in codeigniter?

I have the sdk and facebook login is working fine. I am getting the user details without any problem and problem is only with the profile picture.
If you are geting user profile image then use following function
It work for me
$this->save_profile_photo($socialUser['image']);
function save_profile_photo($link) {
if ($link) {
$img = file_get_contents($link);
$imagename = "/profile" . . '-' . date('y-m-d-H-i-s') . '.jpg';
$file = base_url(PROFILE_IMAGE) . '/' . $imagename;
file_put_contents($file, $img);
}
}

Adding an additional field to login with AWD Facebook Wordpress Plugin

I am using AWD Facebook wordpress plugin to allow my visitors to login with their Facebook account information. When a visitor registers on my site I automatically create a new post that is titled with their username and includes their Facebook profile picture as the content. The code for that is below:
function my_create_page($user_id){
$fbuide = 0;
$the_user = get_userdata($user_id);
$new_user_name = $the_user->user_login;
$new_user_avatar = get_avatar($the_user->user_email);
global $AWD_facebook;
$fbuide = $AWD_facebook->uid;
$headers = get_headers('http://graph.facebook.com/' . $fbuide . '/picture?type=large',1);
if(isset($headers['Location'])) {
$url = $headers['Location']; // string
} else {
$url = false;
}
$my_avatar = "<img src='" . $url . "' class='avatar AWD_fbavatar' alt='" . $alt . "' height='" . $size . "' />";
$my_post = array();
$my_post['post_title'] = $new_user_name;
$my_post['post_type'] = 'post';
$my_post['post_content'] = $my_avatar;
$my_post['post_status'] = 'publish';
wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page');
What I am looking to accomplish is a bit different though. I also want to include a brief biography about the user (currently the post is simply their picture). So when a visitor logs in with AWD Facebook, their needs to be an additional field that allows the user to type in their bio. Then I would be able to grab that info from their user profile and include it in the post. Any ideas on how I can accomplish this? Is there a different way to do this?
I would recommend storing their Facebook picture as metadata and use the content area as their bio for the automatically generated post. So something like this should get you started:
$my_post = array(
'post_title'=>$new_user_name,
'post_type'=>'post',
'post_content'=>'',
'post_status'=>'publish'
);
if( $id = wp_insert_post( $my_post ) ){
update_post_meta($id, 'avatar', $url);
}
Then you can generate the loop like so:
if ( have_posts() ) : while ( have_posts() ) : the_post();
//... stuff here
$avatar = get_post_meta($post->ID, 'avatar', 'true');
the_content();
echo '<img class="avatar AWD_fbavatar" src="'.$avatar.'" alt="'.$alt.'" height="'.$size.'" />';
endwhile;endif;

Facebook PHP SDK empty album

I am working on a Facebook App that get the user Facebook albums and pictures. I all works fine but if the user has an album with no picture in it my app crash because it can't get an album cover and album pictures count. I've tried to escape the foreach that I use but with no success. It "iterate" only the albums prior to the empty one. Here is the raw code snippet:
<?php
$albums = $facebook->api("/me/albums");
foreach ($albums['data'] as $album) {
$album_id = $album['id'];
$album_cover = $album['cover_photo'];
$album_name = $album['name'];
$album_count = $album['count'];
$covers = $facebook->api("/" . $album_cover . "");
$source = $covers['source'];
?>
Some guidance and suggestions are more than welcomed.
Test to see if your album has pictures before getting any data:
$albums = $facebook->api("/me/albums");
foreach ($albums['data'] as $album) {
if (0 < $album['count'] {
$album_id = $album['id'];
...
}
}

Tumblr API get current AVATAR URL

Everyone knows? about avatar url in tumblr api / read / json?
like for example the facebook?
http://graph.facebook.com/[your facebook id]/picture?type=normal
<?php
$tumblog = 'natadec0c0'; // change to your username
// if your Tumblog is self hosted, you need to change the base url to the location of your tumblog
$baseurl = 'http://' . $tumblog . '.tumblr.com';
$request = $baseurl . '/api/read/json';
$ci = curl_init($request);
curl_setopt($ci,CURLOPT_RETURNTRANSFER, TRUE);
$input = curl_exec($ci);
curl_close($ci);
// Tumblr JSON doesn't come in standard form, some str replace needed
$input = str_replace('var tumblr_api_read = ','',$input);
$input = str_replace(';','',$input);
// parameter 'true' is necessary for output as PHP array
$value = json_decode($input,true);
$content = $value['posts'];
$blogInfo = $value['tumblelog'];
// the number of items you want to display
$item = 10;
// Echo the blog info
echo "<h3>" . $blogInfo['title'] . "</h3>\n";
echo "<h4>" . $blogInfo['picture'] . "</h4>\n<hr />\n";
?>
how to append my current avatar?
A better solution for this is to put the Avatar api in an img tag.
api.tumblr.com/v2/blog/{base-hostname}/avatar[/size]
example: <img src='http://api.tumblr.com/v2/blog/myreallycoolblog.tumblr.com/avatar/48'/>
So as long as you have the blogname, you can display the avatar.
I guess you have to use
GET http://www.tumblr.com/api/authenticate?email=user#example.com&password=12345
to get the avatar of the user. The sample response for mine is
<tumblr version="1.0">
<user default-post-format="html" can-upload-audio="1" can-upload-aiff="1" can-ask-question="1" can-upload-video="1" max-video-bytes-uploaded="26214400" liked-post-count="134"/>
<tumblelog title="ABNKKPGPiCTuReNPLaKo?!" is-admin="1" posts="301" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="arvn" url="http://arvn.tumblr.com/" type="public" followers="17" avatar-url="http://28.media.tumblr.com/avatar_b1786ec9e62d_128.png" is-primary="yes" backup-post-limit="30000"/>
<tumblelog title="i kras yu." is-admin="1" posts="1" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="ikrasyu" url="http://ikrasyu.tumblr.com/" type="public" followers="2" avatar-url="http://25.media.tumblr.com/avatar_02a7ef66fce8_128.png" backup-post-limit="30000"/>
</tumblr>
and get the avatar-url field of the corresponding tumblelog. Too bad there is no json format option, maybe use preg_match. You also need the email address and password of the user, or do it via OAuth.
Or you could scrape the tumblelog for the avatar.
$page = file_get_contents("http://{$tumblog}.tumblr.com/");
$avatar = preg_match('/<img src="(http.+)" alt="portrait"/', $page, $matches) ? $matches[1]: 'http://example.com/blank.png';

Getting user info after login for facebook application

I have written a small piece to get the user to login :
<?php
include_once ('facebook.php');
$api_key = 'xxxxxxxxxxxxx';
$secret = 'xxxxxxxxxxxxx';
global $facebook;
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
#Ask user to login if not logged in
$is_tab = isset($_POST['fb_sig_in_profile_tab']);
if( !$is_tab ){
$uid = $facebook->require_login($required_permissions = 'email,status_update,offline_access');
}
else{
$uid = $facebook->get_profile_user();
}
I need to retrieve the users info once I have the uid. Unfortunately I cannot find the api calls for it and there is a no IDE for facebook :(. Can anyone point me to the api's or give me here. I want to get users username, city, zipcode.
I coudnt get this to work : facebook.Schema.user user = api.users.getInfo();
I think it is for the new API lib.
Thanks.
P.S: I am not using graph APIs, because I found them to be poorly documented and I got stuck with them for a while so decided to abandon them atleast for now.
You can get it like this:
$user_info = $facebook->api_client->users_getInfo($uid, "name, city, zipcode");
print_r($user_info);
More Info:
http://developers.facebook.com/docs/reference/rest/users.getInfo