This question already has answers here:
Accessing Facebook Graph API without login
(2 answers)
Closed 5 years ago.
I copied the code below from Facebook Graph Api console. However, Android Studio doesn't recognize accessToken.
I have alread created a Facebook App and I got its acesstoken. But I don't know where to add it in the code. If I just copy and paste. It shows this error
If I use AccessToken.getCurrentAccessToken() method, it will show this error:
errorMessage: An access token is required to request this resource
Here is my code:
GraphRequest request = GraphRequest.newGraphPathRequest(
accessToken,
"/ibm/events",
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.d(TAG, "onCompleted: " + response.toString());
}});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,cover,start_time,end_time,place,description");
parameters.putString("limit", "3");
request.setParameters(parameters);
request.executeAsync();
}
Firstly :
Make a Facebook app with these simple steps I have written below:
Go to Developer tab and click on it.
Then go to Website Option.
Enter the app name which you have want.
Click on Create Facebook App.
After this you have to choose category, you can choose App for Pages.
Your AppId and Appkey is created automatically. The AppSecretKey is obfuscated. You can click on the show button to see your AppId and AppSecurityKey.
Then Check this link to generate access token
1.Copy and Paste Your App ID & Your App Secret into the generator below. You can get your App ID & your App Secret by clicking on the Apps main menu option and then choosing your newely created App.
Next click the Tools Menu and then choose Graph API Exploer.
page1
On this page you will click the Graph API Explorer select option.
Then choose your Application from the list. In this example we'll use Custom Feed.
Now you click on the Get Access Token. This will show a Select Permissions popup as you will see next.
Next Click on the Extended Permissions menu option and click the checkbox read_stream and click Get Access Token. DO NOT CHECK read_stream if you are using our plugin to display a Page on facebook.
6.Then click the Okay button to continue.
Fetch Event IN Android : You have to download Android facebook sdk and put you access token there getCurrentAccessToken() in this method.
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{event-id}",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
Event Details
Related
Is there a way for me to pull Facebook photo album and display it in my app ? I mean with the UI Interface to select the photo, not only to retrieve the url of the photos (via graph api I guess) and later build our-self the ui interface (ie: the gallery) to let the user select the photo.
Is their something like this in the facebook SDK for android/ios ?
You can use to Graph API in Facebook SDK
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{album-id}/photos",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
Facebook Graph API alum photos
Add the compile dependency with the latest version of the Facebook SDK in the build.gradle file:
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.+'
}
facebook getting started
Add Facebook App ID
Then add your Facebook App ID to your project's strings file and update your Android manifest:
Open your strings.xml file. Example path: /app/src/main/res/values/strings.xml.
Add a new string with the name facebook_app_id and value as your Facebook App ID
Open AndroidManifest.xml
Add a uses-permission element to the manifest:
Is it possible that I place a like button on my android app clicking which likes a post which is publicly available on facebook? I do not want any additional windows to open for the task except may be for first time authentication.
All questions asked so far are related to opening a new window.
It is possible. You can perform a Like Action using Facebook's Open Graph API. In order to do so, you need to meet certain conditions:
The viewer of the in-app content is a Facebook user who has Facebook-authed and granted the app publish_actions permission
The in-app content has an Open Graph object page that is properly marked-up using Open Graph metatags
The viewer has intentionally clicked on a custom in-app “like button” associated with the in-app content
Steps at a high-level:
You need to first get the user's active Session (com.facebook.Session).
Session session = Session.getActiveSession();
Then you need to ensure that the user has the publish_actions permission. If not, request them.
List<String> requestedPermissions = Arrays.asList("publish_actions");
List<String> currentPermissions = session.getPermissions();
if (!currentPermissions.containsAll(requestedPermissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, requestedPermissions);
session.requestNewPublishPermissions(newPermissionsRequest);
}
Finally, send your request to "me/og.likes". Your request should include your Session, a Bundle including the Graph object you want to like, the HTTP method, and a callback that will execute once you receive a response.
Bundle postParams = new Bundle();
postParams.putString("object", myGraphObject);
Request request = new Request(session, "me/og.likes", postParams, HttpMethod.POST, myCallback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
You want to perform these steps in your button's OnClickListener.
Hope this helps!
Resources:
Like Action
Publishing Conditions
I have created a custom object called event and I would like people to perform an action called rsvp. I would like people to be able to share this action eg "Mary has rsvped to Some Event"
I have already created the action and configured the sentences now I just need a way to programatically be able to create events. I have tried using the code:
Bundle params = new Bundle();
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me/objects/my_namespace:event",
params,
HttpMethod.POST
);
GraphResponse response = request.executeAndWait();
But I keep getting the error "(#100) The parameter object is required".
My question is What is the step-by-step way from creating open graph stories to sharing them in Android? Also, what does that error mean?
I want to be able to seamlessly publish to a users Facebook feed from the background in my Android application. The user is fully aware of the content they are publishing, but the post will be made after a relatively long upload process, so the user should not be made to wait. I am using the Android Facebook SDK v4.1.2.
I see that I need to request the "publish_actions" permission from the user beforehand:
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-publish_actions
I can use the LoginManager to get the access token:
https://developers.facebook.com/docs/facebook-login/android/v2.3#access_profile
I am then not sure how to share a link to the users feed without using the ShareDialog:
https://developers.facebook.com/docs/sharing/android
This SO question suggests using the Request object for v3.x, which is equivalent to the GraphRequest object for v4.x:
https://developers.facebook.com/docs/reference/android/current/class/GraphRequest/
but I am not sure how to build the correct GraphRequest. I assume I need to publish a message to "/me/feed":
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Can anyone tell me how to do this?
In writing the question I found my own solution from trawling the docs and examples. I need to publish a message to "/me/feed":
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Bundle params = new Bundle();
params.putString("link", link);
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(),
"/me/feed", params, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
}
});
request.executeAndWait();
After obtaining the "publish_actions" permission.
You should use the ShareApi class if you don't want to build the params bundle yourself.
Build a ShareLinkContent as you normally would:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://your.url.com"))
.build();
Then call ShareApi:
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {...});
i am trying to understand new taggable_friends permission added in facebook sdk works?
i am getting all friends list in previous Facebook sdk ,
but in new Facebook sdk its not allowed only those friends will display who are using this app,
is there any way to get all friends list ?
what taggable_friends do ,can i get all list by using this permission?
/{user-id}/taggable_friends
new Request(
session,
"/me/taggable_friends",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();