I am working on an app, which sends a request to the selected user. Am selecting the user through FriendPickerFragment(Android.Support.V4.App). I am successfully getting the list of friends I have selected on the "Done" button of the Picker fragment. Post that, I am trying to build a request dialog, which should not show up in my app, but should send the FB request to the selected friends. Here is my code:
Bundle bundle = new Bundle ();
bundle.PutString ("app_id", AppID);
var dialog = new WebDialog.RequestsDialogBuilder (this.Activity, Session.ActiveSession, bundle).SetMessage(user + " has invited you to join my application");
dialog.Build ();
The problem I am facing is that, the request is not actually sent. There is no exception either. I even implemented the call back:
public void OnComplete(Bundle bundle, FacebookException e)
but the execution does NOT go in the callback. What am I missing here ? Any help would be greatly appreciated.
Tried dialog.SetTo(userId) before build also....still not working...
Any suggestions ?
Well, according to the documentation for RequestDialogBuilder the method public WebDialog build(), the behavior you describe is by design. Quote:
"The dialog is not shown, but is ready to be shown by calling Dialog.show()"
It sounds like you do not want to show a dialog, but just want to send a request without any UI. You are using the wrong tool to do that. To send a request using a dialog, you have to show the dialog, and the user action is what causes a request to be sent. This doesn't require any special permission to be granted ahead of time, because it only sends a request if the user chooses to after your app opens the dialog.
There may or may not be a way to do what you want (send an app request without any user interaction) ... if there is a way, it will be along these lines:
use the Graph API, get a token with some permission that the user grants to your app. Here's a place to start looking:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/apprequests/
Related
I used the following in a straight copy paste from the Parse documentation:
ParseTwitterUtils.logIn(view.getContext(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Twitter!");
} else {
Log.d("MyApp", "User logged in through Twitter!");
}
}
});
with the exception of the context I'm passing to it. Because I'm inside a button click event which is in a fragment, I pass as context: view.getContext()
I have also called: ParseTwitterUtils.initialize("YOUR CONSUMER KEY", "YOUR CONSUMER SECRET");
before everything with my API Key and API Secret. However, there is no Twitter login dialog appearing. What appears is a small rectangle with text saying: "loading..." and a moving circle, but it closes without opening any authentication dialog. Because of that the done() method part is never being called.
I realize that in order to use the ParseFacebookUtils one needs the Facebook SDK for android and that such SDK is the one that contains the Login Screen. In fact, when I use ParseFacebookUtils, it works perfectly. But there is no SDK with login screen for Twitter in Android. Plus the Parse documentation clearly states that a Twitter Login Dialog is supposed to appear when the code above is executed. No further action needed according to it.
What am I missing here. How do I make the Twitter login dialog appear?
Please make sure you have entered your consumer key, and consumer secret correctly. Next please make sure you follow item 3 in the Parse.Com Android developer guide under setup.
That is,
3. When asked to specify a "Callback URL" for your Twitter app, please insert a valid URL. This value will not be used by your iOS or Android application, but is necessary in order to enable authentication through Twitter.
You must specify a callback URL (a valid URL) although it won't be used. That means, use a made up URL or use something like http://myCompanyWebsite.com/callbackurl. This can be set under the "Settings" tab in your twitter developer console.
I don't use Twitter in my Parse applications, but I was able to duplicate the problem by also missing step 3 and then subsequently fix it.
If you are still having trouble please post your logcat of when you press the click button.
A strange behavior occurs when I try to login on facebook through my app. This behavior, however, doesn`t show up on the emulator and on other two devices (Galaxy Y, with Android 2.3.5/2.3.6).
I want to publish some text on my wall. I click on the publish button and then it detects the user is not logged in, a dialog box is shown telling the user that my app wants to publish some information on my behalf. Until here, there`s nothing unusual.
The problem is that after the user presses the "Ok" button, a loading dialog appears and disappears right after. The facebook login screen is not shown and the user is not logged in either.
I receive one exception (which are inexistent on the other devices):
SpannableStringBuilder(24080): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
Code:
private void OpenPublishingConnection() {
if (Session.getActiveSession().isClosed()) {
Session.openActiveSession(this, true, status);
}
if (Session.getActiveSession().isOpened() == false && Session.getActiveSession().isClosed() == false) {
Session.getActiveSession().openForPublish(new OpenRequest(this).setPermissions(Arrays.asList(PERMISSION_PUBLISH)).setCallback(status));
} else {
if (Session.getActiveSession().isClosed() == true) {
Session.getActiveSession().requestNewPublishPermissions(new NewPermissionsRequest(this, Arrays.asList(PERMISSION_PUBLISH)));
} else {}
}
}
public void Publish(Bundle b) {
OpenPublishingConnection();
Request req = new Request(Session.getActiveSession(), "me/feed", b, HttpMethod.POST, callback);
RequestAsyncTask rat = new RequestAsyncTask(req);
rat.execute();
}
It turns out that my app had some kind of conflict with the Facebook App, so I just uninstalled and reinstalled the latter and everything started working just fine.
I can't try another device
If you can no longer access your login email or phone number, and you don't have access to a device you've used to log into this account before, it's not safe for us to give you another way to log in.
We understand that this might not help you get back on Facebook, but we have to take this action to stop anyone who doesn't own this account from getting into it.
I've started making the upgrade to Facebook SDK 3.0 for Android. I've managed to open an active session (using the Session.openActiveSession(...) method) and get the current user's info (using the Request.executeMeRequestAsync(...) method). However! When I try to get the current user's list of friends as follows...
Request.newMyFriendsRequest(
Session.getActiveSession(),
new Request.GraphUserListCallback()
{
#Override
public void onCompleted(List<GraphUser> users, Response response)
{
// never called
}
});
... the onCompleted(...) callback is never called and my user is left hanging, forever. I've checked and my access token is valid and I'm pretty sure no extra permissions are needed to get the current user's list of friends. Any ideas anybody? I'm stuck and Facebook developers bug-reporting is disabled!
Calling Request.newMyFriendsRequest just creates the request, it doesn't execute it.
You need to do something like:
Request request = Request.newMyFriendsRequest(...);
request.executeAsync();
or just
Request.newMyFriendsRequest(...).executeAsync();
On JellyBean device.
I'm following this to request an oauth2 token, e.g.
AccountManager am = AccountManager.get(getActivity());
am.invalidateAuthToken(MY_AUTH_TOKEN_TYPE, null);
am.getAuthToken(aGoogleAccount, MY_AUTH_TOKEN_TYPE, null, this,
new OnTokenAcquired(), new Handler(new OnError()));
and then make the check as per the later code sample:
private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
#Override
public void run(AccountManagerFuture<Bundle> result) {
Bundle bundle = result.getResult();
...
Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT);
if (launch != null) {
startActivityForResult(launch, 0);
return;
}
}
}
I never get a KEY_INTENT. I understand the following:
There may be many reasons for the authenticator to return an Intent. It may be the first time the user has logged in to this account. Perhaps the user's account has expired and they need to log in again, or perhaps their stored credentials are incorrect. Maybe the account requires two-factor authentication or it needs to activate the camera to do a retina scan. It doesn't really matter what the reason is. If you want a valid token, you're going to have to fire off the Intent to get it.
However, the getAuthToken always results in the permission screen, or login screen, appearing before the code hits the run method at which point the token is valid. I've tried:
Turning on 2 step authentication. Account login is requested before run so always have the token in run.
Changing the password on the server. Again account login is requested before run so always have the token in run.
Don't have the ability to try a retina scan so somewhat at a loss.
EDIT 1 The problem I have is that there may be a circumstance where I will get a KEY_INTENT and so I'd rather test this code path now rather when when it's out in the field.
Thanks in advance.
Peter.
Had a chance to do something similar on a project. This not the exactly the same as your code, and I still say that the callback docs have too many 'maybes' to be certain of how it should work, but if you use this method passing false for notifyAuthFailure, you will get an intent with the re-login screen if you change the password or enable 2FA. This is for ClientLogin, but should work similarly for OAuth 2 (not tested though). Something like:
// using Calendar ClientLogin for simplicity
Bundle authResult = am.getAuthToken(account, "cl", false, null, null).getResult();
if (authResult.containsKey(AccountManager.KEY_INTENT)) {
Intent authIntent = authResult.getParcelable(AccountManager.KEY_INTENT);
// start activity or show notification
}
I think you need to call getResult(), like this:
Intent launch = (Intent)result.getResult().get(AccountManager.KEY_INTENT);
You're using the version of getAuthToken which uses an Activity to invoke the access authorization prompt. That version of getAuthToken does not return an intent since the supplied activity is used to launch the corresponding intent. If you want to manually launch an intent, use the version of getAuthToken that was deprecated in API level 14. See the following for more information:
http://developer.android.com/reference/android/accounts/AccountManager.html#getAuthToken%28android.accounts.Account,%20java.lang.String,%20boolean,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler%29
i am using ksoap to get connected with my web services i got response code "000" as login successful on my logcat now my question is that how to handle that response code so that user can go to next page if possible please provide code..
You will need some conditional logic to programmatically decide what to do. If the user gets passed with a successful login, I would think you would want to send them to the main app screen??
if (ResponseCode == "000"){
startActivity (Intent) // where you want the user to go.
}
Else If (ResponseCode == "whateverelse"){
//Restart Login screen
}
Else {
//Your locked out or whatever other scenario you may have.
}
Something like the above will work. THere may also be additional Android login functional;ity, but I just set a boolean and pass it along with the user so I can check his login status when I may beed to.