Follow playlists using Spotify iOS SDK - ios

My requirement is to add a track to a particular playlist using the Spotify iOS SDK, and to make sure the user is following that playlist. In general adding a track is fine unless the user has deleted the playlist in Spotify (which actually just unfollows it), in this case the track is added, but the user cannot see the playlist anymore.
If the user isn't following the playlist, can we follow playlists using the SDK?
Thanks
Jules

Yeah just use SPTFollow (API documentation). Here's an example of a request in Swift 3:
var req = SPTFollow.createRequestFor(followingPlaylist: URL(string: "spotify:user:USERID:playlist:PLAYLISTID"), withAccessToken: (SPTAuth.defaultInstance().session.accessToken)!, secret: false)
SPTRequest.sharedHandler().perform(req) { (error, response, data) in
print("error=\(error), response=\(response), data=\(data)"
var results = SPTFollow.followingResult(from: data!, with: response!)
print("is following? \(results[0])")
}

Related

Share video to Facebook via Graph iOS SDK

I try to upload video to Facebook using Graph API.
But always see error message
(#100) No permission to publish the video.
Facebook app has Development mode. I created test user there. My role is admin. FB access token is valid.
Here my code here:
private func upload(url: URL) {
guard let data = try? Data(contentsOf: url) else { return }
let connection = GraphRequestConnection()
connection.delegate = self
var items: [String: Any] = [:]
items["title"] = "Test title from api"
items["\(url.absoluteString)"] = data
let keys = ["value" : "EVERYONE"]
items["privacy"] = keys
let request = GraphRequest(graphPath: "me/videos", parameters: items, httpMethod: .post)
connection.add(request) { reqconnection, anyInfo, error in
print(reqconnection)
print(anyInfo)
print(error)
}
connection.start()
}
I saw a lot of questions about it, but mostly they are too old and don't work for me.
Share video to FB
From thread FB Developers here - the same error, but they didn't find solution
Also check this docs - doesn't work
Also I'm a bit confused what docs are right for post video in Facebook.
Because in docs I see
The Video API allows you to publish Videos on Pages and Groups. Publishing on Users is not supported.
but also in another docs see Graph API with path me/videos. So it confused me a bit.
What docs are correct for my case:
here
here
From docs I see that
Your app should manage permissions as follows:
Graph API Requests - Before you send Graph API requests, you should check for necessary permissions and request them if needed.
Where can I find permission publish_actions?
Please help to figure out how to fix that.
I only can upload via ShareDialog. Like here and docs here

How to get a Catalog Playlist id for Apple Music API?

I am currently developing a 3rd-party client for Apple Music on iOS devices, but got stuck when trying to fetch artworks for catalog playlists.
According to Apple Music API, "Get a Catalog Playlist", we may fetch a playlist by using its identifier as a path parameter, and the URL of the artwork is contained in the response :
https://developer.apple.com/documentation/applemusicapi/get_a_catalog_playlist
However, the playlist identifier is nowhere to be found, does anyone know how exactly can I access "the unique identifier for the playlist"? Any help would be appreciated!
Code I have tried but did not work:
let playlistQuery: MPMediaQuery = MPMediaQuery.playlists()
let playlists = playlistQuery.collections
guard playlists != nil else { return }
for playlist in playlists! {
print(playlist.value(forProperty: MPMediaPlaylistPropertyPersistentID ))
}
The above code print out strings like: 15225742680232009793
while the correct id samples look like:
pl.acc464c750b94302b8806e5fcbe56e17
Problem solved, in case anyone comes after me wondering, you may use the "Get All Library Playlists" as a web service endpoint to fetch all library playlists (including the ones user-created and Apple shared publicly).
Check in the link: https://developer.apple.com/documentation/applemusicapi/get_all_library_playlists
The response contains pretty much all you need for a playlist.
If anyone has other solutions, you may share them down here, thank you.

How to make IOS app play Spotify Playlist using its Web-API?

I want to create a custom playlist for a Yoga session and want it to be played using our app. I also need to skip some tracks of the playlist when it reaches some certain time interval.
I have tried using Spotify Web API to create a Playlist with custom tracks. But when attempting to use the https://api.spotify.com/v1/me/player/play Endpoint for the required context uri, it throws error for being NON PREMIUM.
I have ensured all the Scopes are being used.
So is there no way to stream without being a premium user ?
Alamofire.request("https://api.spotify.com/v1/me/player/play", method: .put , parameters: parameters, encoding: URLEncoding.httpBody , headers: headers).responseJSON { response in
print("-- USER Playlists Custom --")
}
error = {
message = "Player command failed: Premium required";
reason = "PREMIUM_REQUIRED";
status = 403;
}
Indeed, as the message states music playback via the Spotify API only supports those with a Premium Subscription - you'll need to sign up for one, usually (depending on territory) Spotify offers at least one month free to start with so you could try that but without a premium subscription you won't be able to stream music.

iMessaged-based invitations for GameCenter for iOS 10

I'm trying to update my app to work correctly with the new features of GameCenter in iOS10.
I create a new GKGameSession on device1, get a share URL, and all that works fine. I send the share URL out via a share sheet to device 2.
Device2 clicks the link, the device briefly displays 'Retrieving...' and then launches my app. Great! But, now what? Is there context information available for this URL that I can somehow access? Otherwise I have no way how to respond when the app is launched.
Previously you'd get a callback to something adhering to the GKLocalPlayerListener protocol, to the method player:didAcceptInvite:, and you could join the match that way. But with these iCloud-based messages, the player might not be even logged into GameCenter, right? This part seems to have been glossed over in the WWDC presentation.
Also, as of today (12/28/2016) there is no Apple documentation on these new methods.
Since the GKGameSessionEventListener callback session:didAddPlayer: only fires if the game is already running, to be sure you can process this callback every time requires a work around. I've tested this and it works.
When you send out an iMessage or email invite to the game, don't include the Game Session Invite URL directly in the message. Instead use a registered URL that will open your app when opened on a device on which your app is installed. Check here to see how:
Complete Tutorial on iOS Custom URL Schemes
But add a percent escaped encoding of the game invite URL as a parameter to this URL thusly (I'm assuming the registration of a url e.g. newGameRequest but it will be best to make this quite unique, or even better - though it requires more setup, try Universal Link Support as this will allow you to direct users who don't have your app installed to a webpage with a download link)
let openOverWordForPlayerChallenge = "newGameRequest://?token="
gameState.gameSession?.getShareURL { (url, error) in
guard error == nil else { return }
// No opponent so we need to issue an invite
let encodedChallengeURL = url!.absoluteString.addingPercentEncoding(withAllowedCharacters:.urlHostAllowed)
let nestedURLString = openOverWordForPlayerChallenge + encodedChallengeURL!
let nestedURL = URL(string: nestedURLString)!
}
send the URL in a message or email or WhatsApp or whatever. Then in your app delegate, add the following:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
var success = false
if let queryString = url.query {
if let urlStringToken = queryString.removingPercentEncoding {
let token = "token="
let startIndex = urlStringToken.startIndex
let stringRange = startIndex..<urlStringToken.index(startIndex, offsetBy: token.characters.count)
let urlString = urlStringToken.replacingOccurrences(of: token, with: "", options: .literal, range: stringRange)
if let url = URL(string: urlString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
success = true
}
}
}
}
return success
}
Now you can be sure the session:didAddPlayer: will be called. What's the betting this workarround is good for about 2 weeks, and they fix this in the next release of iOS showcased at WWDC 2017 ! Update: this problem hasn't been fixed - so the workaround above remains good!
I agree, the lack of documentation is frustrating. From what I can see, we have to:
add <GKGameSessionEventListener> protocol in the class' header
Then session:didAddPlayer: fires on the joining player's device after accepting an invite link.
update:
Unfortunately, I'm not surprised to hear your results. I hadn't tried all of those scenarios, but GKTurnBasedMatch had similar shortcomings. The way I got around it there was: I added a list of player statuses to match data (invited, active, quit, etc). I gave the player a view of "pending invitations." When they opened that view, I would load all of their matches and display the entries where the player was in invited state. With GKGameSession, that should work too.
Or, it might be easier if you could maintain a local list of sessions that you are aware of. Whenever the game becomes active, pull the entire list of sessions from the server and look for a new entry. The new entry would have to be the match the player just accepted by clicking the share URL.

How do I use the YouTube Data API in my iOS app? I get "Access not configured" error on each request

I want to use the YouTube Data API to get the links to thumbnails for a specific YouTube video in my iOS app. I went to Google Developers Console and created a new project.
For that project I then went to "APIs" and removed the default APIs it enables for me and added the YouTube Data API. I then went to credentials, created a Public Key (as I don't need the user to log in or anything, just getting the thumbnail URLs) as iOS, which gave me an API key. I added the Bundle Identifier for my project under Allowed Applications.
Now in my app I tried the following code:
let test = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=*MYKEYHERE*&part=snippet,contentDetails,statistics,status")!, completionHandler: { (data, response, error) -> Void in
let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
println("JSON: \(json)")
})
But it prints out the error:
JSON: Optional({
error = {
code = 403;
errors = (
{
domain = usageLimits;
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
reason = accessNotConfigured;
}
);
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
};
})
What exactly am I doing wrong?
There is a known problem about Bundle id in the console. If you can just remove that restriction, it should just work fine.
You can track the original issue from here: https://code.google.com/p/gdata-issues/issues/detail?id=5770
Here's what you need, YouTube has a service API via web to consult this types of things. I'm using this URL to consult all videos from a user (getting every videos: URL, Thumbnail, views, duration, etc). I'm sure you'll find thumbnails for a particular video. Its a JSON response so you'll have to take a good look to the structure but can't get simpler than this.
http://gdata.youtube.com/feeds/api/users/USER_NAME/uploads?v=2&alt=json&#&start-index=1&max-results=10

Resources