SoundCloud API: Tweeting on upload and disable comments - soundcloud

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!

Related

laravel4 hybridauth facebook Authentication failed! Facebook returned an invalid user id

OK, I'm trying to use Hybridauth with laravel 4. However I seem to be getting the very common when trying to log in with facebook:
Authentication failed! Facebook returned an invalid user id.
I have read all the other posts, and have had no luck, so just hoping someone may be able to help me.
I followed this tutorial: http://www.mrcasual.com/on/coding/laravel4-package-management-with-composer/
And have tried several other configurations to no success.
Here is my config/hybridauth.php
<?php
return array(
"base_url" => "http://myapp.dev/social/auth/",
"providers" => array (
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "****", "secret" => "****" ),
),
),
);
And here is my route:
Route::get('social/{action?}', array("as" => "hybridauth", function($action = "")
{
// check URL segment
if ($action == "auth") {
// process authentication
try {
Hybrid_Endpoint::process();
}
catch (Exception $e) {
// redirect back to http://URL/social/
return Redirect::route('hybridauth');
}
return;
}
try {
// create a HybridAuth object
$socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
// authenticate with Facebook
$provider = $socialAuth->authenticate("Facebook");
// fetch user profile
$userProfile = $provider->getUserProfile();
}
catch(Exception $e) {
// exception codes can be found on HybBridAuth's web site
return $e->getMessage();
}
// access user profile data
echo "Connected with: <b>{$provider->id}</b><br />";
echo "As: <b>{$userProfile->displayName}</b><br />";
echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";
// logout
$provider->logout();
}));
So, when I access "myapp.dev/social" I'm brought to the facebook sign up page everthing seems to work fine, asks me to allow permissions to myadd.dev. After I click OK I am brought to the following URL: http://myapp.ie/social#_=_ where the error is displayed.
Not sure if this is relevant:
Just from observing other sites that in-cooperate a facebook login.. the redirect URL looks something like http://somesite.dev/subdomain/#_=_ . In other words they have a slash before the #=. Is this my problem, how do I fix it?? Very new to hybridauth so any help greatly appreciated thanks.
Oh I do realize that this post is very similar to other posts but I have yet to find a solution.
UPDATE: the exact error: Authentification failed. The user has canceled the authentication or the provider refused the connection.
In base_facebook.php do following
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 50,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.2',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
protected $trustForwarded = true;
protected $allowSignedRequest = false;
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
at modules/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php:128
solved!
For anyone else this is what worked for me: I reset app secret and now works great. No idea why my first app secret key did not work. Spent a ridiculous amount of time trying to fix this error.
Had this error in the past. Solved by modyfying Hybridauth's code myself.
In thirdparty/Facebook/base_facebook.php make sure $CURL_OPTS array uses:
CURLOPT_SSL_VERIFYPEER => false
In my case I was closing session files for performance improvements so I added:
session_start()
inside Storage.php wherever HA::STORE session var is being updated/unset.
Let me know if it helps.
CURLOPT_SSL_VERIFYPEER => false & resetting my app secret key didn't work for me. I was getting this error because of some conflict with privileges I had previously setup. Removing the app from my facebook account did the trick (under privacy settings -> apps).
REMOVE THE TRAILING SLASH !!! (in config/hybridauth.php)
"base_url" => "http://myapp.dev/social/auth/",
should be
"base_url" => "http://myapp.dev/social/auth",
My case was a little bit more specific, but just in case: Be carefull with redirects!
I had an SSL Certificate installed and a redirect to force the user over https, but when I first configured HybridAuth I didn't took this into account. The facebook request was being redirected over to https causing the $_REQUEST data to be lost in the process.
For me the change was, in Hybrid/config.php:
"base_url" => "http://my-site.com/"
to
"base_url" => "https://my-site.com/"
I was having the same issue (although using HybridAuth on Yii) and turns out my app on Facebook was still in Sandbox mode. No source code changes needed on HybridAuth, just needed to turn off Sandbox Mode for the app and suddenly everything worked. Hope this helps.
This happened to me because my SSL is terminated in AWS's load balancer
Just update the config file in your app/config to include the trustForwarded setting
<?php
return array(
'base_url' => 'http://website.com/oauth/auth',
'providers' => array (
'Facebook' => array (
'enabled' => true,
'keys' => array ( 'id' => 'redacted', 'secret' => 'redacted' ),
'trustForwarded' => true,
),
),
);
I had the exact same error message on a wordpress installation using Hybridauth. To find the problem I set up an isolated test with the Facebook PHP SDK (which Hybridauth uses) just to find out that curl_exec was not enabled on my host. Happily, an easy fix.
If you are on apache open you php.ini and delete curl_exec from this line:
disable_functions = curl_exec
Reload your apache configuration and voila :)
Hope this will help somebody.

Posting on facebook page - i am the only one who sees the post

I searched all web long for this problem but nothing seems to fix it.
I am simply writing a post to a facebook page, the post is visibile on the page but only by myself and no from other admins or users.
How can it be possible?
I am using this function (also i'm pretty sure that the whole code is working as the post is on the page!):
$postResult = $facebook->api($post_url, 'post', $msg_body );
First i was guessing that was a privacy problem, but the page doesn't have that kind of parameter.
Whole code is:
post_url = '/'.$page_id.'/feed';
$page_info = $facebook->api("/$page_id?fields=access_token");
//die(print_r($page_info));
//posts message on page statues
$msg_body = array(
'access_token' => $page_info['access_token'],
'message' => "test"
);
if ($fbuser) {
try {
$postResult = $facebook->api($post_url, 'post', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}
#------------# EDIT #------------#
I still have the same problem, also, i checked a feed "manually" posted and a feed from my script, and the fields are exactly the same... that's insane.
#------------# EDIT II: #------------#
I tried with a curl, nothing seems to work :/
Problem has been solved.
As an idiot, SandBox mode was activated (i didn't know that eveything done by the app was binded by the SandBox).
You need some kind of page access token to do that.
Also, what $post_url, stands for? We can't guess from the code you wrote. Anyhow, you post either with $pageid/feed or with me/feed (and an access token). It should be something like $facebook->api( '/me/feed/', 'post', array('access_token' => $page_access_token, 'message' => 'Test message', 'link' => 'http://somelink.com') );

Facebooks Link preview

I've searched and searched and searched and cannot find a way for a person to post a link on a page from an app (As the page owner, of course), and have a link preview. It just posts the link instead of a preview like it would if you were posting via facebook. I would like to know if there is a way to override the link preview like this:
$x = $facebook->api('/'.$_POST["id"].'/link', 'post', array('message'=> urldecode($_POST["message"]), 'access_token' => $_POST["auth"], 'cb' => '', 'picture' => 'url to pic','description'=>'blah blah'));
Please help, don't really know what else to do..
Consider using a link shorter service that allows customization of link preview. With linkfork.co you can customize the image, title, and description.
I did a lot of testing and came up with my answer:
$x = $facebook->api('/'.$_POST["id"].'/links', 'post', array('link' => $url,'caption' => $data['description'],'name' => $data['title'],'picture' => $data['thumbnail_url'],'url' => $url, 'message'=> urldecode($_POST["message"]), 'access_token' => $_POST["auth"], 'cb' => ''));

Zend_Feed: white screen of death on Production, works perfectly on Dev Server

A few weeks ago I noticed that the RSS feed on my live site was broken - I get a white screen of death. It had worked fine up until then. The rest of my site continues to work fine. Additionally the identical code continues to work perfectly on my dev box.
No code changes have occurred, so I'm guessing my web host have changed a server setting - but I've no idea what the setting may be (so I don't know if there's a workaround or if I need to ask my web host to change something). Both Prod & Dev are running PHP 5.3.8.
Could anyone give me a clue as to what that setting might be?
The only major difference I could see in the response headers was that my (non-working) Production RSS feed has this Response Header: "Accept-Ranges: none".
I've double-checked the DB call that populates the feed, and even replaced it with some static data within the class (just in case there was a DB problem), but it makes no difference.
Code for the relevant Controller method below:
public function articlesAction(){
$format = $this->_request->getParam('format');
//default format to rss if unspecified
$format = in_array($format, array('rss','atom')) ? $format : 'rss';
$articles = new Application_Model_DbTable_Articles();
$rows = $articles->getLatestArticlesForFeed();
$channel = array(
'title' => 'Feed of articles',
'link' => 'http://www.mysite.co.uk',
'description' => 'The latest articles and reviews from my site',
'author' => 'My name',
'language' => 'en',
'ttl' => '60',
'copyright' => '© the writers of the articles',
'charset' => 'utf-8',
'entries' => array()
);
foreach ($rows as $item) {
$articlelink = 'http://www.mysite.co.uk/articles/' . $item['stub'];
$formattedlink = '<p><strong>Source: '.$articlelink.'</strong></p>';
$channel['entries'][] = array(
'title' => $item['title'],
'link' => $articlelink,
'guid' => $articlelink,
'description' => $formattedlink . $item['content'] . '<p>© ' . $item['byline'] . ', ' . $item['copyright'] . '</p>' ,
'lastUpdate' => strtotime($item['date_published'])
);
}
$feed = Zend_Feed::importArray($channel, $format);
$feed->__wakeup();
}
$feed->send();
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
}
I wasted an hour once figuring out why I have a WSOD just because I initiated a class with one lowercase letter...
$table = new Model_DbTable_EshopSubcategories(); instead of
$table = new Model_DbTable_EshopSubCategories();
The dev server does not have to be case sensitive and the production server can.

Send notification or post on wall

i have been going crazy and cant figure out how to make a script for my application that would allow the user to select a friend and send them a notification or post on their wall from my application.
I just need to notify their friend that they have been challenged to play a flash games, just a simple text with a link, i dont need anything fancy :D
Here is what i tried and it doesnt work :( no idea why.
$message = 'Watch this video!';
$attachment = array( 'name' => 'ninja cat', 'href' => 'http://www.youtube.com/watch?v=muLIPWjks_M', 'caption' => '{*actor*} uploaded a video to www.youtube.com', 'description' => 'a sneaky cat', 'properties' => array('category' => array( 'text' => 'pets', 'href' => 'http://www.youtube.com/browse?s=mp&t=t&c=15'), 'ratings' => '5 stars'), 'media' => array(array('type' => 'flash', 'swfsrc' => 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1', 'imgsrc' => 'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=', 'width' => '100', 'height' => '80', 'expanded_width' => '160', 'expanded_height' => '120')));
$action_links = array( array('text' => 'Upload a video', 'href' => 'http://www.youtube.com/my_videos_upload'));
$target_id = $user;
$facebook->api_client->stream_publish($message, $attachment, $action_links, $target_id);
UPDATE:
appinclude.php
$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827&redirect_uri=https://apps.facebook.com/gamesorbiter/&scope=publish_stream');
Error i get:
{
"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (https://apps.facebook.com/gamesorbiter/) must be in the same domain or be in a subdomain of an application's base domain (gamesorbiter.com). You can configure the base domain in the application's settings."
}
}
Without the extra "s"(http) i get this error:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Please if you could post an example.
Also do i need extended permission to do that or if the user sends the message i dont need that ?
Thank You
Also do i need extended permission to
do that or if the user sends the
message i dont that ?
Yes, you need the offline_access and publish_stream extended permission from the users.
Update:
In your appinclude.php file, put code like this:
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();
$facebook->redirect('https://graph.facebook.com/oauth/authorize?
client_id=[YOUR APP ID]&
redirect_uri=[YOUR APP URL]&
scope=publish_stream, offline_access');
Replace [YOUR APP ID] with application id that you can see from application settings where you created the site in Facebook Developers section. Also replace the [YOUR APP URL] with your app url.