Question

This is one that I'm beginning to think is a bug, please, Please prove me wrong:

I want to programmatically friend a user on Facebook; they are only and most certainly someone the person knows IRL.

The following three solutions all have the same result: a successful friends dialog--meaning the profile name, picture, statement indicating the action( to friend someone ), and refusal/confirm buttons; pressing 'confirm' is the problem: it leads to a Facebook error presented in the standard fb UI saying "Sorry, something went wrong We're working on getting this fixed as soon as we can". My user is logged in and the fb app id( fb_app_id ) is golden, or the fragment's parent activity would not be called, my to-be-friended user id ( Id ) is also golden, confirmed by their profile picture showing up both in my app and in the friends dialog, the action "friends/" is correct--'friends/?' gives me a good ol' "not found" error--and the OnCompleteListener works fine even around the message.

First way is with the SDK, my preferred if it worked:

Bundle params = new Bundle( );
params.putString( "id", Id );
WebDialog requestsDialog = (
new WebDialog.Builder( this.getActivity( ),
        getString( R.string.fb_app_id ),
        "friends/", params )
    .setOnCompleteListener( new CompleteListener( ) )
    .build( ) );
requestsDialog.show( );

Save the explicit action call, that looks good, doesn't it? It certainly gets me to the confirmation dialog; second way is quick and dirty, but it should work:

String requestUrl = "https://www.facebook.com/dialog/friends/?id="+
    Id+"&app_id="+getString( R.string.fb_app_id )+
    "&redirect_uri=http://www.facebook.com";
WebDialog requestDialog = new WebDialog( this.getActivity( ), requestUrl );
requestDialog.show( );

But it doesn't; same quasi-successful result. The third way was me just checking to make sure I wasn't an idiot, and is essentially the suggestion in this post Facebook friends dialog returns "Unknown method" error but with WebDialogs ( my OnCompleteListener implementation ) instead of the deprecated library. Same thing, same message.

It's not really an error message that's /for/ me, you know? Is this a deprecated API call? Is the error message literally correct and the good folks at fb are aware of this? Is there some param i'm actually missing here? It's not like they aren't signed in! I'm kind of at my wit's end on this one, thanks in advance for the help/advice/calming words. -AnB

P.S. 'friended' looks really funny when you write it out. AB

Was it helpful?

Solution

So, it is a bug on facebook, one that they are aware of, and one that they are not going to fix any time soon ( shortage in developer talent? "strategy"? I'll ask Mark... ). Hearing this dissappointing news, I then tried the url in chrome a few different ways, and big surprise: it works fine when you request the desktop site on the confirm screen.

So, there is one way left to us mobile devs, and that is to make a dialog that jails a webview with

  1. a desktop-seeming user-agent
  2. a URL override to stop the fb website from redirecting through Intent.ACTION_VIEW

here's my implementation (in a fragment):

private void sendRequestDialog( ) {
    String requestUri = "https://www.facebook.com/dialog/friends/?id="+
         Id+"&app_id="+getString(R.string.fb_app_id)+
         "&redirect_uri=http://www.facebook.com";
    WebView webView = new WebView(this.getActivity());
    webView.getSettings().setUserAgentString(getString("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0"));
    webView.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            return false;
        }
    });
    webView.loadUrl(requestUri);
    AlertDialog.Builder dialog = new AlertDialog.Builder(this.getActivity());
    dialog.setView(webView);
    dialog.setPositiveButton("Done", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
    dialog.show();

Of course, you'll want to make those strings references, but this works and looks good in the UI.

Onwards! -AnB

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top