CocoaSoundCloudAPI crashes when I connect to company FaceBook account. Fix required - soundcloud

(I've previously tried SoundCloud GoogleGroups (defunct?), and directly to my SoundCloud contact for this. Told to post the issue here.)
Just trying to get to grips with SoundCloudAPI on iOS and I found a nasty error. Either this is a bug in the API, or a bug in SoundCloud, or (most likely) I'm doing something wrong. :) But the end result would be a broken app, so I'm keen to understand what is going wrong here.
I set up a new iOS project, following the Tobias video, and the CocoaSoundCloudAPI readme.
Using theSCShareViewController I connect to a test SoundCloud account I made for my company. I then create a new connection within the app to a test company FaceBook account. I click install, and Allow All permissions.
The app then hangs, with Terminating app due to uncaught exception 'NSInvalidArgumentException'
on the line (in SCRecordingSaveViewController.m) :
cell.textLabel.text = [connection objectForKey:#"display_name"];
Whenever I run the app now, it crashes on this line.
When I dump out the contents of the connection NSDictionary, it looks like there are two connections listed in self.availableConnections, a "facebook_page" connection with the display_name I gave for my company FaceBook page. But also a second "facebook_profile" with a null display_name. It's this second connection that is causing the API to crash. Presumably the API developers were never expecting a null display_name, but also I don't understand why it's listing two FaceBook connections at all.
If I investigate the value of "display_name" further then Xcode tells me "Variable is not a CFString" and indeed if I look at the class then it is not.
Going into SoundCloud in a browser, I can list the connections, and it shows two of them. One with the name of my company FB account, and a second one:
"http://facebook.com/profile.php?id=***** is your primary Facebook user account"
If I disconnect both of these I can use the SoundCloudAPI again without it crashing.
I then created new personal test SoundCloud and FaceBook accounts, and did the same thing again within the app. This time it did not crash (and in fact worked great), and the connection NSDictionary has one connection "facebook_profile" with a valid display_name. SoundCloud via a browser also lists just one connection.
Note that this also happens with CocoaSoundCloudDemo with no code changes.
I can also hack around with the code to avoid crashing when connecting to my company account:-
// cell.textLabel.text = [connection objectForKey:#"display_name"];
id displayName = [connection objectForKey:#"display_name"];
if ([displayName isKindOfClass:[NSString class]])
{
cell.textLabel.text = (NSString*)displayName;
}
...which gives me two rows with FB connections, but the second is blank. With some effort I can work out what they are doing here in the code, and not show a row if the display_name is invalid, but obviously I'd rather not have to do that and use the standard API code.
SO, long story short:-
1) Does SoundCloud allow you to connect to a company FaceBook account? Is there some special setup you need to do on that FaceBook account so that SoundCloud only sees the "Facebook_profile" and not also "Facebook_page"? The problem seems to be within SoundCloud itself, and not the iOS API, but it is the API that crashes.
2) From my test app, if a user tries to connect a SoundCloud account to a company FaceBook account (at least, with the minimal setup that I have in mine), then the SoundCloudAPI will crash with an exception, and my entire app will continue to crash until the user logs on with a browser to SoundCloud and removes the two connections manually. Surely this can't be good, but I've Googled for anyone with a similar issue and found nothing. Without finding a fix for this I can't use the full API in my app for fear my users will hit the same crash bug, and perhaps will have to create a cut-down custom UI that avoids the need to share to FaceBook etc.

sorry that we have not come back to you earlier.
It is always good to receive feedback from our SDK users and yes we should check
against nil values and handle this case accordingly.
However, I investigated the situation you are describing and actually it worked
flawlessly for me. Two rows for Facebook were displayed properly as soon as I
connected my SoundCloud account w/ the new Facebook page in my SoundCloud profile settings.
You can also check which accounts are connected by running
curl "https://api.soundcloud.com/me/connections.json?oauth_token=<YOUR_OAUTH_TOKEN>
In my case I received something like this
{
"kind": "connection",
"id": 12345678,
"created_at": "2013/01/10 15:55:20 +0000",
"display_name": "Testpage",
"post_publish": true,
"post_favorite": true,
"type": "facebook_page",
"service": "facebook_page",
"uri": "https://api.soundcloud.com/connections/12345678"
},
{
"kind": "connection",
"id": 12345679,
"created_at": "2013/01/10 11:07:56 +0000",
"display_name": "Rob",
"post_publish": true,
"post_favorite": true,
"type": "facebook_profile",
"service": "facebook_profile",
"uri": "https://api.soundcloud.com/connections/12345679"
}
So while uploading a new sound via the SDK, I got two Facebook rows in
the sharing section. Are you still experiencing this issue?
We will release an update to our iOS SDK soon, so stay tuned and thanks for your feedback.

Related

Facebook login - what on earth am I doing wrong

I'm tearing my hair out here.
We've got a web app that is hosted on a bunch of different domains and we have a facebook login on the page. This works just peachy. Most of them run of our root domain eg newsite.ourplatform.com and we reuse the same facebook app and add a new domain in.
We've had a request to set up a new site on a different url. In the past, this hasn't really been a problem. We set up a new facebook app, add the appid to out config and voila, facebook login working. (we don't do this so often, so I've potentially broken it)
This time around. I've set up a new app id and plugged it in, but whenever I call the facebook login, it authenticates me, but I get a useless response from facebook.
eg. On a working site I call
FB.api("/me/", function(response){console.log(JSON.stringify(response));});
and get response
"{id":"12345678910","email":"my#email.com","first_name":"My Name","gender":"male","last_name":"Myname","link":"https://www.facebook.com/app_scoped_user_id/12345678910/","locale":"en_GB","name":"My Name","timezone":10,"updated_time":"2014-01-19T10:44:20+0000","verified":true}
but on the broken site I do the same call and get a response
{"name":"MyName","id":"12345678910"}
Which is sort of good, but I need their email. As far as I can tell, I'm not asking for any permissions beyond email,public_profile and user_friends
Because of the way the app setup works, we have different apps running 2.1, 2.2 and 2.4 and this new one on 2.4 doesn't work. I'm not sure if that's a red herring or if I've got a misconfigured facebook app.
(edit - removed the sites affected to protect the innocent)
As #CBroe said you really need to checkout the v2.4 changelog for the API. In version 2.4 of the API Facebook introduced 'declarative fields'. This means that when you make a base request, like to /me you will only get a small amount of info back, e.g. 'name' and 'id'.
You have two options to get more fields:
Option One
FB.api('/me?fields=first_name,last_name,gender', function(response) {
console.log(response)
});
Option Two
FB.api('/me', function(response) {
console.log(response)
}, {'fields': 'first_name, last_name, gender'})
This will return a response that looks like the following:
{"first_name":"First", "last_name":"Last", "gender":"gender", "id":"ID"}
The key in the request above is specifying the fields URL parameter in your request and is documented in the link #CBroe linked and I have linked above.

Facebook UserId returned from Azure Mobile Services keeps changing within the same Windows Phone app

I'm a newbie to app development. I am building a Windows Phone 8.1 app and have followed the tutorial here: http://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-windows-store-dotnet-get-started-users-preview/ to add authentication using Facebook. Everything seems to work fine, except that every now and again it appears to stop bringing back any data from my Azure database. Further investigation revealed that the UserId that is being shown from the code below, changes periodically (although I can't quite work out how often it changes).
// Define a member variable for storing the signed-in user.
private MobileServiceUser user;
...
var provider = "Facebook";
...
// Login with the identity provider.
user = await App.MobileService.LoginAsync(provider);
// Create and store the user credentials.
credential = new PasswordCredential(provider,
user.UserId, user.MobileServiceAuthenticationToken);
vault.Add(credential);
...
message = string.Format("You are now logged in - {0}", user.UserId);
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
This code is identical to the code in the tutorial. The Facebook app settings (on the Facebook developers site) confirm that I am using v2.3 of their API so I should be getting app-scoped UserIds back. I have only ever logged in with one Facebook account, so I would expect the UserId to be the same each time, but they're not. The UserId is prefaced with 'sid:', which someone on the Facebook developers group on Facebook itself says stands for Session ID, which they would expect to change, but if that's the case, I can't work out where to get the actual UserId from that I can then store in my database and do useful things with. I'm sure I must be doing something basic wrong, but I have spent hours Googling this and cannot (unusually) find an answer.
Any help would be greatly appreciated.
Thanks!
So dug deeper. This is how Mobile Apps work (I was thinking from a Mobile Services perspective). The issue here is that the Gateway doesn't provide static SIDs, which is what User.userId provides. The work around to this is listed in the migration doc.
You can only get the Facebook AppId on the server.
ServiceUser user = (ServiceUser) this.User;
FacebookCredentials creds = (await user.GetIdentitiesAsync()).OfType< FacebookCredentials >().FirstOrDefault();
string mobileServicesUserId = creds.Provider + ":" + creds.UserId;
You should note, that this Id is directly connected with your Facebook App registration. If you ever want to migrate your App to a new Facebook App, you'd have to migrate them. You can also use the Facebook AppId to look up the user's global facebook Id via the Facebook Graph API, which you could use between applications. If you don't see yourself using multiple apps, etc., you can use the Facebook AppId just fine.
Hard to tell what's going on to cause you to use a SID instead of the Faceboook token (which like Facebook:10153...).
It may be faster to rip out the code and reimplement the Auth GetStarted. Maybe you missed a step or misconfigured something along the way. If you have the code hosted on github, I can try to take a look.
Another thing you can do is to not trust the user to give you their User id when you save it to a table. On your insert function, you can add it there.
function insert(item, user, request) {
item.id = user.userId;
request.execute();
}
That should, theoretically, be a valid Facebook token. Let me know if that doesn't work; can dig deeper.

android facebook login button does not work

I'm following this tutorial "Facebook Login Flow for Android" (https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/) to create a simple app containing only one facebook login button to test facebook login.
However, I've been having trouble logging in facebook with this button.... I've been following every step in this tutorial and I've double checked everything -- it is exactly the same as in this tutorial. I see other people who have similar problems are always because of incorrect debug hash code. But I've checked like a million times that I got the correct debug hash code. Some people say that if you wanna release an app, you need a release code. However, I'm not releasing my app -- I'm just testing it on an android device, so I guess I dont really need a release code to do that?
Also, I've checked that I've included my facebook application id for this app in the Android Manifest. So basically, everything I did was strictly following the tutorials on Facebook Developers.
I've seen some people suggesting to use the "keytool" in JDK 6 in stead of JDK 7. And I've checked that I actually did generate my debug hash code with the "keytool" in JDK 6.
So I've tried everything, but the problem still exists!
In that Android Tutorial, it suggests putting this in your code so that you can monitor your LogCat to see if your current state is logged in or logged out:
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
In my case, no matter how many times I clicked Facebook Login Button, I always got "Logged out..." in my LogCat.
Also, the funny thing is, I can't even log in facebook using those sample apps coming with Facebook Android SDK 3.0.1 (eg. SessonLoginSample)!!!!! When I click the login button in those sample apps, nothing happens -- which means I'm not successfully logged in.
I really hope you guys out there can help me with this problem. It's weird I don't see other people with the exact same problem (as I said, those with similar problems are always because of incorrect debug code, but I've checked mine, it is 100% correct). THANK YOU SO MUCH!
It happened to me once. You might have added the export key hash in facebook developer setting.
Add these lines to your code to get your debugging key hash and then add to facebook.
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}

Heroku - Application Error, but no error in logs

I'm hacking away at a Facebook app on Heroku, using Node.js. When I go to the app myself, it works exactly as I expect. When I send another developer/tester to it, the standard Heroku "Application Error" message is displayed. When I check the logs, there isn't even a log that the developer made a GET request for the app page, let alone an error.
He tells me that the last thing he sees in his browser status bar is "waiting for .herokuapp.com", which implies that Facebook got to the app, but the logs don't support this theory.
Is there another method of seeing Heroku errors? Is there something I have to turn on in order to see more? A setting I have to modify to let this other guy use the app?
Update: Some more looking around led me to check the network traffic. He's getting a 503 Service Unavailable, followed by the error page. Still wondering why this happens on his machine, but not mine.
Update: Inserted some error-checking code into the handle_facebook_request method.
req.facebook.app(function(err, app) {
if(err !== null) {
var errorMessage = "Error getting app: " + util.inspect(err['error']);
console.log(errorMessage);
}
// rest of req.facebook.me, and rendering code
}
This gives me an "Unsupported get request", of type "GraphMethodException" and code 100. So now I have something I can look into! I wish that Heroku had at least mentioned that the request had been tried.
I had the same problem with a new facebook app created with the support heroku / node.js.
After several attempts and tests I saw that I get the message "Unsupported get request", type "GraphMethodException" and the code 100, because my facebook app was with sandbox mode.
When I disabled the sandbox my application on heroku it worked fine.

"message": "Invalid redirect_uri:"

So a few months ago my facebook app worked, and now I get a:
{ "error": { "type": "OAuthException", "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration." }
So I googled about that, and read that the cause might be that I didn't specify a site domain in the app settings. So I did that, but Facebook told me that this won't work unless I also specified a website or mobile device adress. But up to now I had this just set as App and neither Website nor mobile thingy. So now I also have to check "website" in addition to "application?" This is confusing.
Anyway, so I thought "whatever" and set it also as website in the app settings. But I still get the same error.
I read something about a channel file? So I have to create one of those or something?
I'm lost and thankful for any advice.
This error is almost always when you're trying to redirect the user to a URL other than your app or website, check that you're actually redirecting them to the correct place