Play SoundCloud links through Soundmanager2 - soundcloud

I'm using the Soundmanager Mp3 Button on my site. However, I'd like to use the Soundcloud Api to stream tracks through Soundmanager instead of hosting MP3's. Basically, I'd like to stream a Soundcloud link through the Soundmanager button. Possible?
I've tried creating a jQuery loop (below) but still haven't had any luck.
<ol>
<li><a class="sm2_button" href="http://soundcloud.com/....">Track Title</a>
</li>
</ol>
and the jQuery
$("ol a").each(function()
{
var thisLink = $(this);
var track_url = this.href; // save href value of each link to 'track_url' i.e. soundcloud.com/...
this.href = this.href.replace(track_url, "#"); // replace href value with '#'
var consumer_key = 'My Consumer Key';
// now resolve the stream_url through Soundcloud's getJSON method
$.when($.getJSON('http://api.soundcloud.com/resolve?url=' + track_url + '&format=json&consumer_key=' + consumer_key + '&callback=?', function(track) {
url = track.stream_url + '?consumer_key=' + consumer_key;
})).done(function() {
// and place an 'onclick' on each link
$(thisLink).attr('onclick', "if (basicMP3Player.lastSound) { basicMP3Player.lastSound.stop(); } document.getElementById('mp3').type='audio/mpeg'; document.getElementById('mp3').href = '" + url + "'; basicMP3Player.handleClick({target: document.getElementById('mp3')});");
});
});

This was driving me nuts too. After a bunch of digging I was able to get it to work if I specified an mp3 mimetype in the link:
<ol>
<li><a type="audio/mp3" class="sm2_button" href="https://api.soundcloud.com/tracks/49349198/stream?client_id=YOUR_CLIENT_ID">Track Title</a></li>
</ol>

You could also try using the SoundCloud Javascript SDK, which'll take care of most of this for you.
SC.initialize({
client_id: "YOUR_CLIENT_ID",
redirect_uri: "http://example.com/callback.html",
});
SC.stream("/tracks/293", function(sound){
sound.play();
});

I tried this and thought I had it...anyone see anything?
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
SC.initialize({
client_id: "My Consumer Key",
redirect_uri: "My Redirect",
});
SC.get("/users/MYUSERID/tracks", {limit: 1000}, function(tracks){
alert("Latest track: " + tracks[0].title);
});
$(".sm2_button").live("click", function(sound){
sound.play();
});
</script>
<script>
$(document).ready(function() {
$(".sm2_button").each(function()
{
var thisLink = $(this);
var track_url = this.href; // save href value of each link to 'track_url' i.e. soundcloud.com/...
this.href = this.href.replace(track_url, "#"); // replace href value with '#'
var consumer_key = 'My Consumer Key';
// now resolve the stream_url through Soundcloud's getJSON method
$.when($.getJSON('http://api.soundcloud.com/resolve?url=' + track_url + '&format=json&consumer_key=' + consumer_key + '&callback=?', function(track) {
url = track.stream_url + '?consumer_key=' + consumer_key;
})).done(function() {
// and place an 'onclick' on each link
$(thisLink).attr('onclick', "if (basicMP3Player.lastSound) { basicMP3Player.lastSound.stop(); } document.getElementById('mp3').type='audio/mpeg'; document.getElementById('mp3').href = '" + url + "'; basicMP3Player.handleClick({target: document.getElementById('mp3')});");
});
});
}); </script>

Related

How to hide facebook post link/caption parameter from facebook javascript sdk

I'm using Facebook JavaScript SDK to post on different Facebook's users Pages, from my custom HTML form,
My HTML FORM contains Following fields
title=>textbox,
Link url=>textbox,
picture=>textbox,
message=>textarea
but the issue I'm facing is that when user did not entered LINK URL in field(blank), and entered Picture URL in picture URL fieldbox then facebook showing PICTURE HOST name in wall instead showing blank or no link URL / picture URL.
CODE which I am using for post my status on pages
FB.api('/' + d + '/feed', 'post', {
message: my_message,
link: url,
name: title,
picture: picUrl,
description: desc,
access_token: b.access_token
}, function (a) {
if (!a || a.error) {
alert('Error occured')
} else {
alert('Message Posted Successfully.')
}
})
link: url
picture: picURL
I tried to submit by comment "link" parameter but still facebook showing picture host URL address on wall.
so i need to know how to stop showing picture host URL address on wall if user did not submit link URL
In the Facebook post you can refer this link as an Caption you just need to keep some space into the Caption Parameter. If you are using string.empty then it will print the you IP Address/Domain Name.
Here i am providing you the sample Code for that...
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
//Get your Facebook API Key from Web.config
appId: '<%=ConfigurationManager.AppSettings["FB_API_KEY"].ToString() %>',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
};
(function () {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
you need to create div to add the script into it.
Now, I am Calling the postToFacebook() function from the ServerSide, you can do that as per your requirement. So, Here is the function of that.
function postToFacebook() {
var POST_NAME = "Post Name";
var POST_DESCRIPTION = "Post Description";
var POST_MESSAGE = "";
//Here I am Leaving some space in the Caption to avoid link name
var POST_CAPTION = " ";
var body = 'Reading Connect JS documentation';
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me/feed', 'post', { body: body, message: POST_MESSAGE, caption: POST_CAPTION, name: POST_NAME, description: POST_DESCRIPTION, picture: document.getElementById('hfImageURL').value }, function (response) {
if (!response || response.error) {
//alert(response.error);
alert('Image is not posted.');
} else {
alert('Image is posted.');
}
});
}
}, { scope: 'offline_access,publish_stream' });
}
I am storing the Image URL into the HiddenField having ID hfImageURL, and give that to the picture property of the Post.
So that's it you can check that code... Working fine for me...
Have a Nice DAY...

Persisting Facebook data into Mongodb (Node.js + Express + jade)

I am developing simple web app that asks for Facebook access token and retrieve 'post' data of logged-in user.
After clicking 'login', it calls FB.api to retrieve user posts and use innerHTML in javascript to update user-status:
<div id="fb-root"></div>
<div id="user-info"></div>
<div id="user-email"></div>
<div id="user-status" name="post"></div>
<button id="fb-auth">Login</button>
My goal is to persist these updated data into mongodb.
What i have tried is to force to submit the form when the post is retrieved and pass the data in 'name="post"', However, this makes the page refreshes again and also the value shows undefined.
Javascript:
FB.api('/me/posts', { limit: 100 }, function(response) {
var userStatus = document.getElementById('user-status');
for (var i=0, l=response.data.length; i<l; i++) {
var post = response.data[i];
if (post.message) {
userStatus.innerHTML = userStatus.innerHTML + ' ' + post.message ;
var form = document.createElement('form');
form.setAttribute('method', 'post');
form.style.display = 'hidden';
document.body.appendChild(form);
form.submit();
} else if (post.attachment && post.attachment.name) {
alert('Attachment: ' + post.attachment.name);
}
}
});
app.js(req.param('post') is undefined, thus mongodb injects undefined data):
app.post('/', function(req, res){
postProvider.save({
posts: req.param('post')
}, function(error, docs){
res.redirect('/')
});
});
Any advice will be greatly appreciated.
Thank you for your time.
To get form data you have to use:
req.body.post

Facebook credit api problem

I am using facebook credits api and using its pay method, following is my code:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
'appId' : '<?php echo $app_id; ?>',
'session' : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
'status' : true, // check login status
'cookie' : true, // enable cookies to allow the server to access the session
'xfbml' : true // parse XFBML
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
FB.Canvas.setAutoResize();
};
(function() {
FB_RequireFeatures(["CanvasUtil"], function() {
FB.CanvasClient.scrollTo(0, 0);
window.FB = null;
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
});
}());
</script>
<script type="text/javascript">
function placeOrder() {
var order_info = { "title":"Music Mood Points",
"description":"Get Music Mood Points to purchase avatars",
"price":"10",
"product_url":"abc"
};
// calling the API ...
var obj = {
method: 'pay',
order_info: order_info,
purchase_type: 'item'
};
FB.ui(obj, callback);
}
var callback = function(data) {
if (data['order_id']) {
writeback("Transaction Completed! </br></br>"
+ "Data returned from Facebook: </br>"
+ "<b>Order ID: </b>" + data['order_id'] + "</br>"
+ "<b>Status: </b>" + data['status']);
} else if (data['error_code']) {
writeback("Transaction Failed! </br></br>"
+ "Error message returned from Facebook:</br>"
+ data['error_message']);
} else {
writeback("Transaction failed!");
}
};
</script>
function writeback(str) {
$('.get_points').html(str);
}
</script>
And here is button to click:
<input type="button" onclick="placeOrder();" value="GET More POINTS NOW" />
So when I click the button , it says in a facebook popup: Your application is not responding correctly.
So is there some thing missing in code or some thing that need to specify from application settings. Do any one have any idea. Any little thing you can tell is appreciated.
thanks in advance
When you place an order Facebook is making an backend call to your server (to the path set in the application setting page (under credit section).
That error means your application is not replying correctly to that initial call (there are actually two that will take place)
See http://developers.facebook.com/docs/creditsapi/
for more including sample code for your backend.

Set a custom redirect after user accept permissions - Facebook Application

I try to build an app and i want to ask for permissions first, so the code below do just these but when it redirects, is transfer me in the domain i host the application.
Is it possible to set a custom redirect?
thanks a lot!
<html>
<head>
<title>Client Flow Example</title>
</head>
<body>
<script>
var appId = "YOUR_APP_ID";
if(window.location.hash.length == 0)
{
url = "https://www.facebook.com/dialog/oauth?client_id=" +
appId + "&redirect_uri=" + window.location +
"&response_type=token";
window.open(url);
} else {
accessToken = window.location.hash.substring(1);
graphUrl = "https://graph.facebook.com/me?" + accessToken +
"&callback=displayUser"
//use JSON-P to call the graph
var script = document.createElement("script");
script.src = graphUrl;
document.body.appendChild(script);
}
function displayUser(user) {
userName.innerText = user.name;
}
</script>
<p id="userName"></p>
</body>
</html>
I guess you only have to change this part :
"&redirect_uri=" + window.location +
To
"&redirect_uri=THE_URL_YOU_WANT" +
But I'm not sure I understand your question correctly ? Could you clarify ?

Facebook Login with Open Graph

//if user is logged in - do this
function login() {
FB.api('/me', function(response) {
document.getElementById('fb-info-block').innerHTML =
"Welcome, " + response.name + ".<br /><br />" +
"<fb:like href = 'www.whitbreaddesign.com' show_faces = 'false' width = '100' action = 'like' colorscheme = 'light'></fb:like>";
});
}
Can someone tell me how I can add the facebook users profile pic to the above code...After someone connects to my site they will get a Welcome, (their name) to my site....How can I also add there profile picture after Login along with the Welcome note?
I hope by now you've solved this but if not you need to use the access token supplied by the getLoginStatus response.
Check out: http://developers.facebook.com/docs/api
The example links for Users, Pages, Events etc are misleading. If you hover over the links you'll see that Facebook adds "?access_token=%TOKEN%" to each link. That's what you'll need to do.
You function will probably look something like this depending on how you work it.
Hope this helps.
window.fbAsyncInit = function()
{
FB.init({ appId: 'Your App Id', status:true, cookie:true, xfbml:true });
FB.getLoginStatus(function(response){
if(response.session){
/* Fetch Access Token Data Here and set to Global Var */
var access_token = response.session.access_token;
/* Other Init Functions */
}
});
function login()
{
FB.api('/me', function(response){
/* Use Access Token Data Here */
document.getElementById('fb-info-block').innerHTML = (
"Welcome, " + response.name + ".<br /><br />" +
'<br/><img src="https://graph.facebook.com/me/picture?access_token='+ access_token +'"/><br/>'+
"<fb:like href = 'www.whitbreaddesign.com' show_faces = 'false' width = '100' action = 'like' colorscheme = 'light'></fb:like>"
);
});
}
}
<img src="http://graph.facebook.com/me/picture">
Why don't you use fbml tags:
fb:profile-pic and fb:name
(http://developers.facebook.com/docs/reference/fbml/)
And once, you put that FBML inside your div, you may need to call
FB.XFBML.Parse() javascript function.
(It pre-exists as I assume you must have included facebook's javascript by now)
The me shortcut will only work if the person is logged in to fb. You can also use their facebook Id:
<img src="https://graph.facebook.com/220439/picture">