Facebook API posting with PHP <5.5 without CurlFile class - facebook

I'm having trouble uploading a file to facebook with PHP versions before 5.5 where CURLFile class is not available.
As I understand, I should use #filepath as the source and that should work, but for some reason it returns
Exception occured, code: 353 with message: (#353) You must select a video file to upload.
I've tried sending the path using realpath() function, that doesn't work.
$response = (new FacebookRequest(
$session, 'POST', '/me/videos', array(
'source' => '#'.realpath($url),
'description' => $description,
'title' => $title
)
))->execute()->getGraphObject();
Does anyone have a solution for this?

Related

Successful Message Push To StockTwits, Chart Not Showing

I can successfully post a message. However when I try with a chart, I get back a success code (200) with the following URL's in the response:
http://charts.stocktwits.com/production/large_.png
http://charts.stocktwits.com/production/small_.png
When I Try to view the message in StockTwits, I get image not found
http://stks.co/p2kuK
I assume there should be some code after large_ and small_; hence the image not found.
Since no errors came back in JSON Response, I assume everything worked OK.
Link to Chart I'm uploading with API:
http://tradescribe.com/images/performance_graphs/AStrakaus-3GTakeover-5day.png
Any ideas?
The message appears in StockTwits without the Chart so API call looks to be correct
Code
$postdata = array(
'access_token' => <TOKEN>,
'body' => <MESSAGE INFORMATION>,
'chart' => <FULLY QUALIFIED URL TO IMAGE>
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.stocktwits.com/api/2/messages/create.json',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postdata
));
We have fixed an issue on our end that was causing this problem and shouldn't be happening anymore.

Zend_Service_Twitter and Twitter API 1.1 (ZF 1.12.3)

I've upgraded to Zend Framework v1.12.3 because it supports the TwitterAPI v1.1 with Zend_Service_Twitter. Before, I've used the TwitterAPI 1.0 (prior ZF 1.12.3) which works well, but that's gonna change in march 2013.
If I call the TwitterAPI v1.1 with the following ZF 1.12.3 code, I keep getting a strange error which I can't explain to myself:
Code:
$twitterService = new Zend_Service_Twitter(array(
'consumerKey' => $this->config['consumerKey'],
'consumerSecret' => $this->config['consumerSecret'],
'username' => $twitterVO->getTwitterUserName(),
'accessToken' => $accessToken // unserialized object
));
$response = $twitterService->statusesUpdate("TEST");
And that's the error which I get. It doesn't matter which function I call (in this case it's statusesUpdate("Test")):
The message is "Invalid chunk size "" unable to read chunked body". The "type" attribute within the array shows a "->". That's also a bit suspect but I couldn't find out where it comes from.
Does anyone have a working example with Zend Framework 1.12.3?
Since ZF 1.12, the Twitter app Oauth parameters can be given in the Zend_Service_Twitter constructor, but consumerKey and consumerSecret must go under the "oauthOptions" array.
This works for me:
$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken('YourAccessToken');
$accessToken->setTokenSecret('YourAccessTokenSecret');
$twitter = new Zend_Service_Twitter(
array(
'username' => 'YourUsername',
'accessToken' => $accessToken,
'oauthOptions' => array(
'consumerKey' => 'YourConsumerKey',
'consumerSecret' => 'YourConsumerSecret'
)
)
);
$result = $twitter->statusesUserTimeline('TEST');

how to set album privacy settings using facebook graph api

Is there any way to change the Facebook album privacy settings with graph api?
I'm trying to find out, but all I could found is how to get the privacy settings using fql, but not to set.
I'm creating the album as follow
$postdata = http_build_query(array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
) $context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false, $context));
$albumid = $result->id;
Now if I add privacy=>"value", it gives $albumid=null.
I'm not sure where I need to add privacy parameter.
When you create an album, you can send these parameters in post request.
name, message, location and privacy.
Value of privacy field can be set like this,
privacy={value: "CUSTOM"} (send this as post parameter)
The value field may specify one of the following strings:
EVERYONE, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM .
As facebook docs sucks, there's no mention about it on albums object page.
However, you can read it on post object.
Edit: (after comments)
In php sdk you can do something like this,
$ret_obj = $facebook->api('me/albums', 'POST',
array(
'privacy' => '{value: "CUSTOM"}',
'location' => 'India'
));
The document of creating an album is put in https://developers.facebook.com/docs/reference/api/user/#albums
Privacy setting is a json-style string. So you could create an array() and use json_encode() to generate it.
with php sdk it is also possible as php style #kaur
$ret_obj = $facebook->api('/me/albums/', 'POST', array(
'source' => '#' . $photo,
'message' => 'Picture uploaded',
'location' => 'Goran',
'privacy'=> array('value'=>'EVERYONE'), //'privacy'=> '{value: "EVERYONE"}', //worked too!! SELF, ALL_FRIENDS, EVERYONE
)
);

SoundCloud API: Tweeting on upload and disable comments

The following PHP code uploads a new track to SoundCloud successfully, but the tweet is not sent.
Is there something I need to have in there as well in order to do this?
$track = $soundcloud->post('tracks',
array(
'track[asset_data]' => '#audio.mp3',
'track[title]' => "my audio",
'track[description]' => "Updated: " . date('l jS F Y h:i:s A'),
'track[sharing]' => 'public',
'track[shared_to][connections][][id]' => '123',
'track[sharing_note]' => 'Have a listen to'
));
Also I'd like to be able to disable comments on the audio I upload, but I wasn't sure what the parameter for that would be too?
Thanks!
dB
I'm unable the repro the sharing problem. Please note that sometimes sharing on other social networks doesn't happen right away. Are you still having trouble? Here's the code I used:
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud("foo", "bar");
$client->setAccessToken('ACCESS_TOKEN');
$track = $client->post('tracks', array(
'track[title]' => 'Foooo',
'track[asset_data]' => '#/Users/paul/audio.wav',
'track[sharing]' => 'public',
'track[shared_to][connections][][id]' => 'CONNECTION_ID',
'track[sharing_note]' => 'Check it out'
));
print_r($track);
Also verify that your CONNECTION_ID is correct. Some code to get a list of connections so you can verify the id:
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud("foo", "bar");
$client->setAccessToken('ACCESS_TOKEN');
print_r(json_decode($client->get('me/connections')));
Unfortunately there's no way currently to disable comments via the API. I'll file a bug and see about getting this fixed.
Hope that helps!

Posting Attachment Facebook Graph API

Right now I'm trying to figure out how to post an attachment using facebooks graph api.
Right now I'm using
$attachment = array(
'message' => $_POST['tt'],
'text' => 'Download',
'name' => 'name',
'href' => 'http://www.url.com',
'description' => ' description!',
'media' => array(array(
'type' => 'mp3',
'src' => $url,
'href' => 'http://www.url.com/',
'title' => $title,
'artist'=> 'artist',
'album'=> 'the album')));
$statusUpdate = $facebook->api('/me/feed', 'post', $attachment);
Problem is it's only posting the message, nothing else, no attachment or anything.
Does anyone have any idea why?
Thanks
Attachments aren't yet supported by the Graph API.
Per the documentation
Arguments message, picture, link,
name, caption, description, source
See my answer in your other question for a workaround.
You have to use the old php SDK until graph supports attachments... Graph only supports photoupload.
Im mixing Graph and old SDK without problems..