gpt4 book ai didi

android - 从 Android 应用程序签到 Facebook

转载 作者:行者123 更新时间:2023-11-30 01:25:35 26 4
gpt4 key购买 nike

我正在尝试从我正在开发的 Android 应用程序执行 Facebook Checkin。我知道我们必须使用图形 API。但是我不确定要让它工作需要什么。有这方面的示例代码吗?

我查看了此链接:Publishing checkins on facebook through android app

如何使用此代码?对此的任何帮助表示赞赏。

public class FBCheckin extends Fragment implements View.OnClickListener {

Button checkin;

public String pageID;
String FACEBOOK_LINK = "https://www.facebook.com/pizzaguydelivery";

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

super.onCreateView(inflater, container, savedInstanceState);
final View rootview = inflater.inflate(R.layout.fblogin, container, false);
checkin.setOnClickListener(this);

return rootview;
}



@Override
public void onClick(View v) {
LoginManager.getInstance().logInWithPublishPermissions(getActivity(), Arrays.asList("publish_actions"));
pageID = FACEBOOK_LINK.substring(FACEBOOK_LINK.lastIndexOf("/") + 1, FACEBOOK_LINK.length());
new GraphRequest(AccessToken.getCurrentAccessToken(), "/" + pageID, null, HttpMethod.GET, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */

try {
if (response.getError() == null) {
JSONObject obj = response.getJSONObject();
if (obj.has("id")) {
pageID = obj.getString("id");

Bundle params = new Bundle();
params.putString("message", "Eating");
params.putString("place", pageID);
// params.putString("link", "URL");

if (pageID == null) {
//Toast.makeText(getApplicationContext(),"Failed to check in",Toast.LENGTH_SHORT).show();
} else {
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/feed", params, HttpMethod.POST, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {

if (response.getError() == null) {
//success
} else {
//Toast.makeText(getApplicationContext(),"Failed to check in",Toast.LENGTH_SHORT).show();
}
}
}).executeAsync();
}
}
}
} catch (JSONException q) {
// TODO Auto-generated catch block
//Toast.makeText(getApplicationContext(),q.getMessage(),Toast.LENGTH_SHORT).show();
q.printStackTrace();
}


}


}).executeAsync();
}


}

最佳答案

以下代码仅通过 pageid checkin 具有 facebook 页面的位置。 (比如餐馆。)但认为您也可以使用地点 ID 来做到这一点。

    LoginManager.getInstance().logInWithPublishPermissions(
getActivity(), Arrays.asList("publish_actions"));
String PAGEID = FACEBOOK_LINK.substring(
FACEBOOK_LINK.lastIndexOf("/") + 1,
FACEBOOK_LINK.length());
new GraphRequest(AccessToken.getCurrentAccessToken(), "/"
+ PAGEID, null, HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */

try {
if (response.getError() == null) {
JSONObject obj = response
.getJSONObject();
if (obj.has("id")) {
pageID = obj.getString("id");
/* make the API call */
Bundle params = new Bundle();
params.putString("message", "Eating");
params.putString("place", pageID);
params.putString("link","URL");
if (pageID == null) {
MessageBox
.Show(getActivity(),
"Failed to check in to this restaurant");
} else {
new GraphRequest(AccessToken
.getCurrentAccessToken(),
"/me/feed", params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(
GraphResponse response) {

if (response.getError() == null) {
//success
} else {
MessageBox
.Show(getActivity(),
"Failed to check in to this restaurant");
}
}
}).executeAsync();
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
MessageBox.Show(getActivity(),
"Error: " + e.getMessage());
e.printStackTrace();
}


}

}
}).executeAsync();

我知道这段代码有点乱,但它可以完成工作。在这里,我要做的第一件事是要求用户获得 facebook 发布许可。然后我通过图形请求检查我正在检查的 pageID 是否有效。如果它有效,那么我将通过另一个请求将用户签到他想要的位置。

关于android - 从 Android 应用程序签到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470753/

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