This question already has an answer here:
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:
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.
Event Details