upload into my soundcloud account using my web form and api? - php

I'm creating a mobile application which plays music stored in my SoundCloud account.
Is there any way to create an automatic login to my SoundCloud account (PHP)? I don't want each user to have to use OAuth because it is only accessing my account and they will have already logged into my site.
Basically i just want to have a list of users tracks, and have the users be able to add or delete tracks from this account with my web form.
All the documentation I've seen uses OAuth to log into individuals accounts but i only want to access my account.
any help or a direction to look would be great
thanks

I was able to login in to a soundcloud account programmatically in PHP using the undocumented (in PHP as yet!) credentialsFlow function:
$sc_client_id = "Client ID from the developer page on soundcloud for your app";
$sc_secret = "Client Secret from the developer page";
$sc_user = "your soundcloud account user";
$sc_pass = "your soundcloud account password";
// create client object and set access token
$client = new Services_Soundcloud($sc_client_id, $sc_secret);
// login
$client->credentialsFlow($sc_user, $sc_pass);
Then you can upload audio files using the $client variable, e.g. this code, taken from 'Uploading Audio Files', http://developers.soundcloud.com/docs#uploading
// upload audio file
$track = json_decode($client->post('tracks', array(
'track[title]' => 'This is my sound',
'track[asset_data]' => '#/absolute/path/to/file.mp3'
)));
// print track link
print $track->permalink_url;

Here's my suggestion: have your users create individual SoundCloud accounts for themselves, then create an interface that allows them to share individual tracks with you, which you can then aggregate into a playlist of some sort (which could then be streamed to whatever device you wish, via SoundCloud).
This has the following advantages:
You maintain control of your own personal SoundCloud account and don't have to worry about it expanding to an unmanageable size.
You have the ability to moderate tracks, allowing you to screen for copyrighted or troll content.
It's more extensible -- if you use something like Drupal's aggregate facility, or a plugin like FeedWordPress (not sure what your CMS platform is, if any), the RSS feeds of tracks you're using can also be taken and used elsewhere by your users, thus potentially increasing the size of your audience. I.e., a widget that displays the latest tracks people can drop onto social profiles or blogs or whatever.
If set up well enough, your solution might be able to encompass non-SoundCloud streaming sources -- YouTube, etc.
Basically, you're dumping links sent to you into an RSS feed, which are super easy to work with both cross-browser and cross-OS. I'd personally use Drupal for this, but I'm sure there are ways to do this just as easily in Joomla!, WordPress or any other CMS worth its salt.

Looks like you can parse the track data in JSON format
http://api.soundcloud.com/tracks?client_id=#{client_id}&limit=10&format=json
There's no "login" either. You're just grabbing a user's public tracks.
Soundcloud has a whole developer API that you should probably brush up on.

Related

What is Facebook app canvas and page tab?

I have spent a lot of time reading FB dev docs and tutorials but I am still very confused with what canvas app and page tab are and how to use them.
What I am expecting from using FB SDK in my site is to have "continue with facebook" button on login screen , have a couple of share and like buttons and send notifications to facebook if user have allowed that. My site has internal messaging system and I want to notify users that new message or activity has happened in my site. In this way users would not have to check my site every day for activity which is important user experience as I expect rare activity(approx. few activities per week).
I have everything running but after user clicks on notification he is taken to canvas app. FB docs and tutorials focuses on code examples but I have not found anywhere description on what canvas app really is. Without this fundamental understanding I can not complete my notification logic, can not understand the terms involved like "secure canvas url" and basically does not feel confident about user experience(which I would want to make as great as possible).
If I google "what is facebook canvas app" I get "Canvas is an immersive and expressive experience on Facebook for businesses to tell their stories and showcase their products.". Apparently from comment below thats something else...
I would appreacite If someone could explain in plain word and maybe example what is canvas app and how should I use if taking into account that my main goal is to notify users about acitivity in my site to their fb account.
I am using CI framework PHP SDK v5.
Background
In Facebook, you create "apps" that run on "platforms". As a quick, very simplified summary, the three primary types of "platforms" that apps can run are:
A website that you host and control, but integrated with the Facebook Graph API (has Facebook Login, posting etc), but otherwise looks like a normal website. You host these on your own servers.
A website designed to sit inside an iFrame on the Facebook Platform. These apps will also generally interact with Facebook Graph. You still host them on your own servers but you have the added advantage that but can get limited information about the user when the page loads.
Stand alone programs (including mobile applications) that also interact with the Facebook Graph.
What you are talking about is the second of these - the iFrame on Facebook.
Facebook provide two ways to embed the application iFrame:
one is a canvas app. This has minimal surrounds for Facebook Header, Footer and a few ads on the right. It maximises your space. (e.g. https://apps.facebook.com/candycrush/?fbs=-1&fb_appcenter=1)
the other is a "page tab" (https://developers.facebook.com/docs/pages/tabs). This is smaller and designed to sit in a company's "Facebook Page" so has less space. As a marketer, however, it keeps everything more branded to your company. (Example: https://www.facebook.com/NutellaANZ/app/595447743881506/)
Note that a single app can run across all the above - canvas, a page tab and a stand-alone HTML page. With some shifting of the API, you can also wrap the same code for mobile and put on the app stores. A user can log in on your mobile app and you can have them logged in on websites and vice-versa (within some limits, but you'll need to explore those).
Games Only?
You are right in that most of the Facebook docs relating to apps refer to games.
Indeed a good place to start is https://developers.facebook.com/docs/games/gamesonfacebook which is where help leads you for Canvas Apps now.
But it doesn't have to be a game - so long as you're using the APIs anything will work. As you mention PHP, have a look at https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas - no mention of a game, but is how you get information from the iFrame in PHP. (There's a lot more reading to do!).
Reading notifications
When clicking on the notification, Facebook will add parameters to the URL. Some of these are determined by the notification (see https://developers.facebook.com/docs/games/services/appnotifications) and others will help you get information about the user (https://developers.facebook.com/docs/reference/login/signed-request, https://developers.facebook.com/docs/php/SignedRequest/5.0.0).
So use this information server-side to work out who the user is and how you want to handle the user. But what experience you want to give the user once you're in the Facebook eco-system is up to you.

Soundcloud + PHP: Authenticating without the Soundcloud screen and uploading tracks

I am building a simple site using the Soundcloud API that needs to do the following:
-- upload tracks to a single account without requesting user authentication (ie., Authenticating without the Soundcloud Screen)
-- display those tracks in a grid or list on a website, and on a map (I will be using the geo-tagging capability)
I am using PHP, which for most of this should be great. However - I am stuck on the authentication and upload piece, and am hungry for help or examples that might allow me to do this with PHP, or if I need to use Ruby or Python, how can I avoid rewriting the pieces I've done in PHP so far, and integrate the two things? If anyone can point me to how this can be done with PHP, that would be perfect!
Thank you.
Upload tracks to a single account without requesting user authentication (ie., Authenticating without the Soundcloud Screen)
Users will have to go to the popup screen. This is quite common for logging into third party services (think about how it works for Facebook Connect, or even for logging into Stack Overflow). It's also a security feature for users: they're effectively giving you the keys to their account, so it should be very clear what's happening.
http://developers.soundcloud.com/docs/api/guide#authentication
Display those tracks in a grid or list on a website, and on a map (I will be using the geo-tagging capability)
This depends on what you mean by "those tracks": if you want all their tracks, then you can just use the API to fetch all tracks by a given user (/users/:user_id/tracks). If it's just the tracks they've uploaded using your app, you have a couple of different options depending on what you want to do.
You can get all public tracks uploaded with your application (/apps/:app_id/tracks), but that would include tracks by everyone, and only public tracks. You could get all tracks by the current user (which would include private tracks) and then filter them inside your application by finding ones created with your app. This information is stored in the "created_with" property. eg:
"created_with": {
"id": 124,
"name": "SoundCloud iPhone",
"uri": "http://api.soundcloud.com/apps/124",
"permalink_url": "http://soundcloud.com/apps/iphone"
}
Displaying them in a grid or a map, I think probably is a different question though...

Mass Wall Post to multiple users?

I have a contest App. And many users have installed the app. I have stored the offline_access tokens of these users. I want to send a message to all users of app at the end of contest. What is the best way to do it. Because when I do it in a while loop the page never loads and browser just shows loading animation gif on tab.
You don't even need the user access tokens to accomplish something similar to what you're trying to do.
First off, mass-wall posting is both a violation of the Facebook Platform Policies (specifically IV.2, IV.3), but it's also really spammy and users will react negatively, probably blocking your app and ultimately it may get banned from Facebook. So don't do that.
Instead, you should utilise the intended social channel for notifying users of new content, App to user Requests.
This is pretty simple to do, as per the Graph API docs for apprequests you just make the following API call:
https://graph.facebook.com/USERID/apprequests?app_access_token=APPTOKEN
Where USERID is each user's Facebook ID and APPTOKEN is always your applications unique access token (see the documentation here if you do not know how to obtain one of those). You will also need to include parameters such as message, which you can read more about in the docs.

Get facebook posts/events/news/gallery with javascript (or php) inside my website

I'm tryin to develop a (almost) 100% client-side dynamic website by integrating it with twitter, facebook and flickr.
I've been able so far to get the last 4 tweets (with javascript) from my client's feed, and now i was wandering if i could do the same with facebook's gallery and events from their feed.
Especially, what i need (given the facebook username/api key/whatever)
gallery
for each gallery in user's profile:
get the gallery name
get the first picture
get the gallery url
news/events
for each news/event/post in user's profile:
get the event name
get the event text
get the event picture (if provided)
get the event url
I don't want to use the facebook widgets with their rendering, i just need to read the json response (if there's any) and put the data inside my website (like a preview).
Since my client is pretty rusty with "computers (cit.)" but he's (not so strangely) comfortable with facebook/twitter/flickr, i tought about a solution like this before adding a database and an admin interface to our website.
I found some resources online, so i think it's possible (in a way or another). I'd like to do it in javascript, but if it's php i won't complain.
Check out this API to get photoes from the user profile
http://developers.facebook.com/docs/reference/api/album/
This is for events
http://developers.facebook.com/docs/reference/api/event/
You can use either the PHP or the Javascript API SDKs:
http://developers.facebook.com/docs/reference/php/
http://developers.facebook.com/docs/reference/javascript/
respectively. Naturally you would handle the returned information differently. Both have a method called api() which can be utilised to grab the album and event objects (as mentioned in another answer):
http://developers.facebook.com/docs/reference/api/album/
http://developers.facebook.com/docs/reference/api/event/
You can pass parameters in the methods to restrict the results returned by fields, number of items, sizes of images etc. This is outlined here:
http://developers.facebook.com/docs/reference/api/
But the issues you are going to face is that you have to authorise your "app" - think website when they use the terminology "app" - to give it permissions to access the information. This takes the form of a two step process. You have to create the app on the Facebook platform which can then access the API methods (only certain information can be got from the API methods without an authenticated app).
The second part is that the user themselves must then authenticate their facebook account against your app - this gives your app permission to access the user's information. In plain English it would go like this:
User visits your webpage; user must be logged into Facebook and must approve your app (this used to be called Facebook Connect for obvious reasons); the app and the user account are "connected"; the app can then use the api methods you've written to return information about the connected user
The beginning explanations of how to do this are here:
http://developers.facebook.com/docs/authentication/
The only way you can access a user's (non-public) information from outside of Facebook is via a connected app and user profile.

Post to multiple user profiles from a Facebook app

I am developing a web application that I want to integrate with both Twitter and Facebook. At a certain time, messages will automatically be published on every user's feed, for both their Twitter and Facebook accounts.
I am currently working on the Facebook component. I know that in order to post to a user's feed on Facebook they must grant my app the publish_stream permission. Suppose I have a database of many users who have granted this permission. I want to publish a message on all of their feeds (visible to their friends). do I need to go through the database one-by-one and do an API call to post the message for each of them? This is the only way I can think of at the moment to do this, and it seems excessive to do this especially as the database gets larger and larger.
Is there a more efficient way to do what I describe?
Thanks.
I say its the only way to do it - anyway - what you say looks like bulk messaging which might be thought as spam from facebook privacy policy point of view. If you want to use facebook's platform to do the spreading of the message, then create a facebook page and make your apps users to like that, otherwise you'll have to do it "by hand" - sending the message to each one of your users. This has a positive side effect - you can personalize the message for each of your user (mention their name, their friends name, etc), making your application more social.

Categories