gpt4 book ai didi

java - 无法将我的 android 应用程序中的 facebook 发布到给定的 postId

转载 作者:太空狗 更新时间:2023-10-29 14:14:18 26 4
gpt4 key购买 nike

我正在尝试从我的 Android 应用程序向给定的 postId = 10154194181895153 发布一个 facebook。

我已经阅读了很多这样做的方法。

但是他们每个人都返回了一个fb响应错误。

你能解释一下A和B的区别吗?

我曾尝试将 A 移动到 asyncTask (C),但如您所见,它没有帮助。

fbLikeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

// fbLike_optionA();
// fbLike_optionB();
fbLike_optionC();

}

选项A

{Response:  responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: android.os.NetworkOnMainThreadException}, isFromCache:false}

.

private void fbLike_optionA() {

SharedPreferences prefs = mOffersListActivity.getSharedPreferences(
PublicMacros.SP_NAME, Context.MODE_PRIVATE);

String fbAccessToken = prefs
.getString(PublicMacros.FB_ACCESS_TOKEN, "");

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

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

选项 B

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 104, errorType: OAuthException, errorMessage: An access token is required to request this resource.}, isFromCache:false}

.

private void fbLike_optionB() {
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {

if (response != null) {
FacebookRequestError error = response
.getError();

if (error != null) {
// error
} else {
// success
}
}
}
};

Request request = new Request(Session
.getActiveSession(), "10154194181895153/likes",
null, HttpMethod.POST, callback);

RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();

}

选项 C

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}, isFromCache:false}

.

private void fbLike_optionC() {
new LikeFbPostAsyncTask(mCurrentlockImage)
.execute("10154194181895153");
}



public class LikeFbPostAsyncTask extends AsyncTask<String, Void, Void> {
ImageButton mLockImage;
Response fbServerResponse;

public LikeFbPostAsyncTask(ImageButton lockImage) {
mLockImage = lockImage;
}

@Override
protected void onPreExecute() {
Log.i("LikeFbPostAsyncTask", "Starting web task...");
}

@Override
protected Void doInBackground(String... fbPostId) {
fbLike_optionA();
return null;
}

@Override
protected void onPostExecute(Void res) {
}
}

选项 D

     Request likeRequest = new Request(Session.getActiveSession(),
fbPostId[0] + "/likes", null, HttpMethod.POST,
new Request.Callback() {

// here is non-ui thread
@Override
public void onCompleted(final Response response) {
Log.i(TAG, response.toString());
fbServerResponse = response;

}
});
Request.executeBatchAndWait(likeRequest);

最佳答案

Original post here .

尝试使用这个库:

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

最简单的添加点赞按钮的方法:

<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"
/>

此 View 将绘制在您的布局中:enter image description here

点击它后,您将看到带有官方 Facebook“赞”插件的对话框。

阅读more details .

关于java - 无法将我的 android 应用程序中的 facebook 发布到给定的 postId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24087245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com