Image not appearing when publishing to stream - php

I'm writing a PHP app that posts to users' feeds. The posts are showing up in the feeds, but the images I'm specifying aren't.
App is currently in sandbox mode, so not sure if that makes a difference.
Here is the data array I'm passing:
$data = array(
'message' => 'I just donated to ORGANIZATION to help end the needless killing of healthy animals.',
'name' => 'Each day over 10,000 healthy pets are killed. Together we can help change this.',
'caption' => 'petbucks.net',
'link' => 'http://petbucks.net',
'description' => 'Sponsorship of real homeless pets gives them the time they need to find a forever home.',
'picture' => 'http://dev.petbucks.net/img/default-donation.jpg',
'actions' => array(
array(
'name' => 'Visit us',
'link' => 'http://petbucks.net'
)
)
);
Facebook::api('/'.$uid.'/feed', 'post', $data);
Like I said, the post is appearing in the user's feed, but the picture isn't. If I inspect the source of where the URL should be, here is the image tag that appears:
<img class="shareMediaPhoto fbStoryAttachmentImage img" src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/y4/r/-PAXP-deijE.gif" alt="" style="background-image: url(https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=332280520247212&v=1&size=z&cksum=534f379420f4d890f47eebaa5bf15f4a&src=http%3A%2F%2Fdev.petbucks.net%2Fimg%2Fdefault-donation.jpg);">
Based on that, I'd say that it's receiving the picture URL just fine (you can see the real URL in the source of that background image), so it must be something else. Is it because of sandbox mode?
Any idea what's going on would be appreciated!
Update
There was some weird DNS issues going on, so those have been fixed. However, I am now seeing full-size images in my main news feed, but not smaller ones in my own newsfeed.
This is going to be hard to demonstrate without giving out access to my FB account, but as an example, take a look at this post which I've made public:
https://www.facebook.com/colin.viebrock/posts/10153814802000226?stream_ref=10
That image shows correctly for me when I'm logged into FB, but not for you I'm guessing. The URL it is trying to display is:
https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=332280520247212&v=1&size=z&cksum=15a4249f3c830d8818ed66e793ba3156&src=https%3A%2F%2Fpetbucks.org%2Fimg%2Fdefault-donation.jpg
When it does show up, it's referencing this image:
https://fbexternal-a.akamaihd.net/safe_image.php?d=AQD1l81SkouNC200&w=154&h=154&url=https%3A%2F%2Fpetbucks.org%2Fimg%2Fdefault-donation.jpg&cfs=1&upscale

Related

Mediaelement.js hover timestamp

I am using mediaelement.js to play Audio in my Wordpress site. I'm having trouble getting it to function exactly like the player on the front page of the mediaelementjs site. Particularly, I want to add timestamps when the user hovers over the audio player so that they can more easily navigate to a particular time. The player is working fine otherwise.
A second, related question. Has anyone found an easy way to add links to particular time stamps in this player (e.g. clicking 1:00 would cause the video to jump to that place without reloading the page). I tried the plugin "Skip to timestamp" but could not get the shortcodes to execute properly within my PHP template.
Sorry I don't have any code up live yet. Here is the code to generate the player.
$attr = array(
'src' => 'myfilepath',
'loop' => '',
'autoplay' => '',
'preload' => 'none',
'features' => array('playpause','progress','current','duration','volume')
);
echo wp_audio_shortcode( $attr );

Cakephp - Getting items from next page in current page?

I'm currently working on a gallery system using cakephp. In it, we have paginated each image album so each page contains a set number of images at most. I have attained this by using:
$this->paginate = array(
'conditions' => array(
'Item.album_id' => $id
),
'order' => array(
'Item.added' => 'desc'
),
'limit' => '50'
);
On my view controller. With this, I can show all the items on each page with no problems.
I'm currently, however, facing a single issue: I need to show, after all the items in the current page, a button that leads to the next page. This is not a problem, except that by design the button that says NEXT PAGE should have an item from the next page as its background.
I have looked around, trying to figure out a way to pull an item from the next page of a paginated system in cakephp without luck. Has anyone done this, or does anyone have a clue how to go about it?
You have to query the preview image manually in the current page.
To access the page number you can use $this->params in the action. Then you have to query images with 'limit' and 'page' parameters as mentioned in the documentation.
After that set the image URL like this:
$this->set('preview_image_url', $queried_url);
Then in the view use inline styling to set the background for the next button.
With Alto's help, I ended up doing this (Putting it here just in case anyone wonders exactly how I did it):
$CurrPage = $this->params['paging']['Item']['page'];
$NextParams = array(
'limit' => 1,
//'page' => $CurrPage + 1,
'order' => array(
'Item.added' => 'desc'
),
'offset' => $CurrPage*50
//'order' =>('rand()')
);
$NextImage = $this->Item->find('first', $NextParams);
$this->set('NextImage', $NextImage);
This gives me the first item from the following page, which is good enough for me. Note the commented 'order' =>('rand()') - I tried to grab a random item from the following page but, alas, it seems like Cake first scrambles all items and THEN paginates. There's probably a way around this, but for now this one did it for me.
Also, using 'page' => $CurrPage + 1 didn't seem to work, with the system instead returning a seemingly randomly chosen image. That's why I instead defaulted to using 'offset' => $CurrPage*50, where 50 is the amount of items per page I'm showing.

SoundCloud - Update Cover / Artwork Image

We use the SoundCloud API to upload tracks with PHP. This is all working perfectly, but we would like to be able to update the track cover artwork with the SoundCloud API. We already upload the cover art when we initially upload the track, but when we try and modify it after the initial upload, it doesn't seem to work (we don't get any errors, it just doesn't get updated and stays the same as it was before).
Is this an intentional limitation of the SoundCloud API or am I missing something?
Edit 1:
I've emailed the SoundCloud API team to ask if they'd just clarify if updating track artwork is possible via the API, but I've had no response (around 48 hours so far).
Edit 2 - 2014-07-08:
4 days on and still no reply yet from the SoundCloud API team? Am I being ignorant thinking this is a simple "yes it should work" or "no that isn't supported with the current API" reply?
Edit 3 - 2014-08-28:
Over 7 weeks and still haven't heard anything from SoundCloud. Looks like they aren't going to be replying!
$track_info_array = array(
'track[title]' => $track['title'],
'track[sharing]' => $track['sharing'],
'track[track_type]' => $track['track_type'],
'track[purchase_url]' => $track['purchase_url'],
'track[description]' => $track['description'],
'track[genre]' => $track['genre'],
'track[label_name]' => $track['label_name'],
'track[tag_list]' => $track['tag_list'],
'track[release_day]' => $release_date[2],
'track[release_month]' => $release_date[1],
'track[release_year]' => $release_date[0],
'track[isrc]' => $track['isrc'],
'track[release]' => $track['release'],
'track[bpm]' => $track['bpm'],
'track[key_signature]' => $track['key_signature']
);
if($release_image){
$track_info_array['track[artwork_data]'] = '#'.$release_image;
}
$track_info = $soundcloud->put('tracks/' . $track['soundcloud_track_id'], $track_info_array);
If it's possible, I believe you want to use PUT instead of a POST request. you also will want to include the track's ID in the endpoint.
Acording to the docs, it is only possible to use artwork_data for uploading, no updates to the audio file nor the artwork.
The fields artwork_data and asset_data have a comment of "only for uploading"
Reference: https://developers.soundcloud.com/docs/api/reference#tracks
Delete all your temporary internet and cache files. It may actually be changing for everyone else but you.
There is a trick that usually works. The Soundcloud API may have some sloppy coding. Try editing the entire URL link for the target file. That should work.

Tagging photos on Facebook with Graph API / PHP SDK

The question is pretty much in the title, but to be more specific, I'm working on a facebook contest for a client in which people have to upload photos to take part in it after accepting rules and subscribing, etc.
After going down a long road full of deceptions
(here's what I tried that didn't work in the end:
uploading to the user's album then tagging the page: nope, can't tag a page
uploading to a public album in the page, like "fan photos", or wall photos? can't find anything AT ALL about a way to do this, though it would've been my preferred way.)
So, I ended up having an idea: I would do this in two steps. First, the user subsribes and uploads a photo to my PHP server. Then, another, different application with permissions on the account that has the page, would take control of it, upload all the photos at 5 minutes intervals (meaning, you subsribe, 5 minutes later, your photo's uploaded.)
So far, so good; I don't like the logic behind this, but it's the only way I found! So, I did the base, I'm able to post a photo with a caption as the page in a dedicated app album.
BUT! I can't tag anyone in those photos. Maybe you can't tag as a page, maybe you can't tag in page albums, maybe I don't have the permissions required (I have stream_publish, user_photos, friends_photos, offline_access, and I could add anything if I need to since it's a private-use app anyway). Oh and, the user I'm trying to tag is the admin for both the app and the page (and he likes the page). I don't know, but it's driving me crazy. I hate the official documentation, there's no example code, you have to figure out most of the things, go through trial and error or search on the web for people who did so and shared how to do things. Not nice when you have little time to complete a project for a client without busting the budget.
Anyway, here's my error I keep getting whenever I try to tag someone to a photo from any album:
OAuthException: (#322) Invalid photo tag subject
And here's the code I'm using to upload a photo from the server to facebook.
if ($user) {
try {
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
// First method, at the same time as upload. Upload works but no tags
$args = array(
'access_token' => $page_info['access_token'],
'source' => '#' . realpath($FILE_PATH),
'message' => "test"
'tags' => array(
array(
'tag_uid'=> "MY_USER_ID",
'x' => 0,
'y' => 0
))
);
$post = $facebook->api("/$page_id/photos","post",$args);
$postID = $post['id'];
// Second method I'm trying. No tags.
$tag = $facebook->api("/$postID/tags/MY_USER_ID","post");
print_r($tag);
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Any help would be appreciated. Thanks in advance!
EDIT :: Now I got it partly working using the second part in the code, but only if I remove the "access_token" parameter from the photo posting first. Basically, it only works if I upload it to a personal album. But that's as far as it gets from what I want. When I upload it to the album from the page, it says I asked for tag requests, but on my personal account which I tagged, I don't receive anything. Baaaah.
RE-EDIT :: After much tries, it seems I can't tag someone as a page or in a page album. I'll try to find an alternative, I guess.

Facebook; posting a link to a fanpage

I have a web application that allows a user to publish a small blurb when one of their articles goes live on their site. Right now I am able to post to the user's wall using a session_key I saved in a table but I can't publish the same link on a fan page (I have the rights and IDs of the pages I need).
Essentially I want the functionality of: http://wiki.developers.facebook.com/index.php/Links.post but for a page instead. So far all I can find utilizes the steam.publish function which isn't quite the same thing.
I'm hoping that there's a hidden parameter (like a target_id) in the link.post function that I've missed (since the facebook wiki is horrible).
Any help is appreciated :) If there isn't a function maybe someone could help me use the parameters of stream.publish to have the content of a post look the same?
Well I couldn't find a way to use the link_post() function to post to a fanpage so I decided to shape the stream.publish result in a way that it would look the same. I had to do a lot of dancing around the variables to get the same effect but it worked. In this case I had to grab the "description" metatag, the first image in the page's content, and the page's title.
I hope this can help someone out:
$title = 'Title of the article, or the title of your webpage';
$message = 'Caption that will go with the link, from the user';
$description = 'I put what would have been in the description metatag, which is what the post link seems to grab';
$fb_thumbnail = ''; // a link to the first image in your article
$target_id = 'XXXXXX'; // the id of the fan page you want to post to
$attachment = array( 'name' => $title,
'href' => 'http://'.$url,
'description' => $description,
'media' => array(array('type' => 'image',
'src' => $fb_thumbnail,
'href' => 'http://'.$url))); // I would get an error with the HREF but that's because I wasn't including the "http://" bit in the link
$attachment = json_encode($attachment);
$facebook->api_client->stream_publish($message, $attachment,"",$target_id);

Categories