I have shared a url from my android app to FB:
I then save aside (hard coded) the postId
I try to do "fb like" to that post
using this code, but get an error:
Button socialBtn3 = (Button) dialog
.findViewById(R.id.socialBtn3);
socialBtn3.setOnClickListener(new OnClickListener() {
String fbPostId = "685560152_10153809399380153";
@Override
public void onClick(View v) {
new LikeFbPostAsyncTask().execute(fbPostId);
}
});
and this:
public class LikeFbPostAsyncTask extends AsyncTask<String, Void, Void> {
public LikeFbPostAsyncTask() {
}
@Override
protected void onPreExecute() {
Log.i("LikeFbPostAsyncTask", "Starting web task...");
}
@Override
protected Void doInBackground(String... fbPostId) {
Request likeRequest = new Request(Session.getActiveSession(),
fbPostId + "/likes", null, HttpMethod.POST,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
Log.i(TAG, response.toString());
// how to return to ui thread?
// return response;
}
});
Request.executeBatchAndWait(likeRequest);
return null;
}
@Override
protected void onPostExecute(Void res) {
}
}
{Response: responseCode: 404, graphObject: null, error: {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: [Ljava.lang.String;@4284cd10}, isFromCache:false}
how can i solve this?
You are sending an array of String arguments to the AsyncTask (String...
). When extracting the desired string from the array you should do :
Request likeRequest = new Request(Session.getActiveSession(),
fbPostId[0] + "/likes", null, HttpMethod.POST,
new Request.Callback() {
instead of:
Request likeRequest = new Request(Session.getActiveSession(),
fbPostId + "/likes", null, HttpMethod.POST,
new Request.Callback() {
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句