0

Here's the flow I am trying to make work:

Activity opens and a Like button is shown to user User clicks on button and Facebook's Login Screen shows up User logins and is directed to Fan Page (via Intent or WebView... or anything else that works :) User likes the page User presses Android's back button and come back to Activity Activity resumes and checks if the user indeed liked the page.

  public class MainActivity extends AppCompatActivity {

    private Button mBtnSubmit;
    private WebView mWebView;
    private final int MY_PERMISSIONS_REQUEST = 1234;
    private MyBrowser myBrowser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mWebView = new WebView(MainActivity.this);
        myBrowser = new MyBrowser();
        mWebView.getSettings().setLoadsImagesAutomatically(true);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mWebView.loadUrl("https://www.facebook.com/rvcjofficial/?ref=br_rs");

        mWebView.setWebViewClient(new MyBrowser());

        setContentView(mWebView);


    }
 private class MyBrowser extends WebViewClient {


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }
    }
}
aarav
  • 53
  • 8
  • "If he did, points are given to him" - you must read the platform policy before creating any app. rewarding users in any way for liking a page is not allowed, it´s called "incentivizing". – andyrandy Sep 29 '16 at 10:06
  • I did this few years ago. You need to set a `webviewclient` and override `shouldOverrideUrlLoading`. You need to check the url (String#contains will work) when the page is like for example i remember the url gives a hint when a page is liked. Best of luck – Muhammad Babar Sep 29 '16 at 10:17
  • @Muhammad Babar i tried your method.i did not get any hint from the url.I updated my code. please see it. and if you know how can i implement this. so please tell me. its urgent. – aarav Sep 29 '16 at 10:56
  • how can something that is not allowed according to the platform policy of facebook be urgent? ;) – andyrandy Sep 29 '16 at 11:07
  • @luschn Dear sir, I am not doing any things that against the facebook privacy. i jss want that when i do the click on the like button of the facebook i will get the indication that page is liked. – aarav Sep 29 '16 at 11:16
  • we know that, but what for? you removed that part where you wanted to give points to a user from your question ;) – andyrandy Sep 29 '16 at 11:19
  • 1
    okey if i like a page this is the url `https://www.facebook.com/ajax/pages/fan_status.php?av=100012757304746&dpr=1` and if i unlike the same page this is the url `https://www.facebook.com/ajax/pages/fan_status.php?dpr=1`. So you must first filter out the url on the base of `fan_status` name and then can check if there is the av parameter found in the url its mean user has liked the page. Please note this is a hacky way and may break in future if facebook decided to change the scheme. – Muhammad Babar Sep 29 '16 at 11:23
  • @luschn Yeah ! because i don't know that it is against the facebook privacy.and i don't want that give points to the user. i want that how can i get that page is liked. if you know the answer please share with me. it is urgent. – aarav Sep 29 '16 at 11:24
  • scraping facebook.com is definitely the wrong way to do this, and it´s not allowed either (see scraping terms of facebook). you MUST use the graph api, and the answer from febi tells you how to get the liked pages with the graph api. – andyrandy Sep 29 '16 at 11:29
  • @MuhammadBabar this is not working.i think facebook changed the scheme. if i likes a page and then unlike the url is same at the both end. – aarav Sep 29 '16 at 11:30
  • this would be the api call to get the info if someone likes a specific page: /me/likes/{page-id} – andyrandy Sep 29 '16 at 11:31
  • i used the web to produce the urls just now. Can you share the url's that you are getting using shouldOverrideUrl method? – Muhammad Babar Sep 29 '16 at 11:32
  • @luschn yes ! febi told me . but i don't know how can i implement this. i knew that this is a nooby but if you know that how can i use that code so please tell me. – aarav Sep 29 '16 at 11:33
  • @MuhammadBabar This is the url https://m.facebook.com/rvcjofficial/?ref=br_rs. – aarav Sep 29 '16 at 11:38
  • you are not getting my point. Please note the url when you press the like button in webview. – Muhammad Babar Sep 29 '16 at 11:39
  • @MuhammadBabar yes ! when i am pressing the like button it gives the same url. you can try also. it gives the same. – aarav Sep 29 '16 at 11:48
  • try intercepting ajax calls. http://stackoverflow.com/questions/3941969/android-intercept-ajax-call-from-webview – Muhammad Babar Sep 29 '16 at 12:02

1 Answers1

1

You can achieve this using the Graph API. Sample code below. /* make the API call */

new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{user-id}/likes",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

Also check this link https://developers.facebook.com/docs/graph-api/reference/user/likes

Febi M Felix
  • 2,799
  • 1
  • 10
  • 13
  • I tried it. but i really don't know how to use it. in user id i am passing the whole link of the page.is it right ?? and please can you tell me how can i use it . – aarav Sep 29 '16 at 10:06
  • just use "/me" instead of the user id: /me/likes. either way, you would need the user_likes permission and you will not get it approved in the login review for like gating or rewarding users for liking your page. – andyrandy Sep 29 '16 at 10:07
  • @luschn can you tell me what can i pass in the user id ? bacause i don't know how to implement it. – aarav Sep 29 '16 at 10:15
  • i just told you...and did you read that other part? that´s the important one, about the platform policy, like gating and rewarding users. – andyrandy Sep 29 '16 at 10:16