Ofir A.
Ofir A.

Reputation: 3162

How to like a website from my Android application

I have an application that show to the user articles from news feeds. I want to add Facebook like mechanism, that when the user push the like button, his Facebook account will show that he is like this article.

So, I downloaded the Facebook sdk, and worked with the open graph example. The problem is that I can't find any good example of how to to this.

I understand that I have action types, and object types. I added action type of me/og.likes and now I need to send the url of the selected article.

What I do so far is:

I have this lines, what they do is only add which type of action my application can handle.

this is working fine.

Bundle params = new Bundle();
params.putString("object", "http://samples.ogp.me/226075010839791");

Request request = new Request(
    Session.getActiveSession(),
    "me/og.likes",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

Now I want to send the actual url of the selected article, do I need to use some kind of outside url of an object or I can build object in my application and send it?

Any help would be great,

thanks.

Upvotes: 0

Views: 140

Answers (2)

Oleksii K.
Oleksii K.

Reputation: 5419

There is library which completely solve this issue (project page):

dependencies {
    compile 'com.shamanland:facebook-like-button:0.1.8'
}

The simplest way to add like button:

<com.shamanland.facebook.likebutton.FacebookLikeButton
    style="@style/Widget.FacebookLikeButton"
    app:pageUrl="http://url.to.like/page.html"
    app:pageTitle="Title of page"
    app:pageText="Short description of page"
    app:pagePictureUrl="http://url.to.like/picture.jpg"
    />

This view will be drawn in your layout: enter image description here

After clicking on it you will see the dialog with official Facebook 'Like' plugin.

Read more details.

enter image description here

Upvotes: 1

Yervand Khalapyan
Yervand Khalapyan

Reputation: 858

When creating an action you must be sure that facebook robot can see the URL and correct meta tags. You can debug your page on this page. So in your case as I understand facebook can't visit your application and therefore can't determine meta tags in your app. So the solution I can offer is creating a web page which will generate meta tags depending on the $_GET[] parameter. You can pass an article ID and generate meta tags for that ID.

Upvotes: 1

Related Questions