问题描述
文档很糟糕。我想发布用户登录到Facebook。根据创建checkin对象的文档已被弃用
而不是你应该添加一个帖子附有位置数据。所以这就是我想要做的。或者也许我应该尝试发布和打开图形故事?
无论如何,这里是我所拥有的,基本上是发布SDK示例中的帖子的代码,该帖子已创建,但没有附加位置数据。 p>
private void publishStory(){
会话session = Session.getActiveSession();
if(session!= null){
Bundle placeBundle = new Bundle();
Bundle locationBundle = new Bundle();
Bundle postParams = new Bundle();
locationBundle.putString(latitude,String.valueOf(place.getLat()));
locationBundle.putString(longitude,String.valueOf(place.getLng()));
placeBundle.putString(id,place.getPage_id());
placeBundle.putString(name,place.getName());
placeBundle.putBundle(location,locationBundle);
postParams.putBundle(place,placeBundle);
postParams.putString(message,test message);
Request.Callback callback = new Request.Callback(){
public void onCompleted(Response response){
String postId = null;
try {
JSONObject graphResponse = response.getGraphObject()。getInnerJSONObject();
postId = graphResponse.getString(id);
}
catch(JSONException e){
Log.i(app.TAG,JSON error+ e.getMessage());
}
catch(异常e){
e.printStackTrace();
}
FacebookRequestError error = response.getError();
if(error!= null){
Toast.makeText(mContext,error.getErrorMessage(),Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(mContext,postId,Toast.LENGTH_LONG).show();
}
}
};
请求请求=新请求(会话,我/ feed,postParams,HttpMethod.POST,回调);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
else {
toast(no session to publish);
}
}
会话确实具有发布权限,它会发布一个帖子,但所有的都有测试消息字符串。该地点的对象来自于Facebook的服务器,因此它是具有page_id的实际位置。当我正在调试post params看起来像这样
Bundle [{message = test message,place = Bundle [{id = 171229079554355,location = Bundle [{longitude = -122.434568,latitude = 37.797314}],name = The Brixton San Francisco}]]]
Session.openActiveSession(activity,true,new Session.StatusCallback(){
//会话更改时的回调状态
@Override
public void call(Session session,SessionState state,
异常异常){
if(session!= null&& session .isOpened()){
//检查发布权限
列表< String> permissions = session.getPermissions();
if(!isSubsetOf(PERMISSIONS,permissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
活动,许可);
session.requestNewPublishPermissions(newPermissionsRequest);
返回;
}
Bundle postParams = new Bundle();
postParams.putString(message,message);
postParams.putString(tags,tag);
postParams.putString(place,place_id);
Request.Callback callback = new Request.Callback(){
private String toastmessage;
public void onCompleted(响应响应){
try {
JSONObject graphResponse = response
.getGraphObject()。getInnerJSONObject();
String postId = null;
postId = graphResponse.getString(id);
} catch(Exception e){
Log.i(Test,JSON error+ e.getMessage());
}
FacebookRequestError error = response.getError();
if(error!= null){
isPosted(false);
Toast.makeText(
activity.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
isPosted(true);
toastmessage =发布成功;
Toast.makeText(activity,toastmessage,
Toast.LENGTH_SHORT).show();
{
}
}
}
};
请求请求=新请求(会话,我/ feed,
postParams,HttpMethod.POST,回调);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
});
The docs are terrible. I want to publish a users check in to facebook. According to the docs creating a checkin object is deprecated
https://developers.facebook.com/docs/reference/api/checkin
and instead you're supposed to add a post with location data attached. So that's what I'm trying to do. Or maybe i'm supposed to try to publish and open graph story?
Anyways here's what I have, it's basically the code to publish a post that is in their SDK sample, the post is created but there is no location data attached.
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null) {
Bundle placeBundle = new Bundle();
Bundle locationBundle = new Bundle();
Bundle postParams = new Bundle();
locationBundle.putString("latitude",String.valueOf(place.getLat()));
locationBundle.putString("longitude",String.valueOf(place.getLng()));
placeBundle.putString("id", place.getPage_id());
placeBundle.putString("name", place.getName());
placeBundle.putBundle("location", locationBundle);
postParams.putBundle("place", placeBundle);
postParams.putString("message", "test message");
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
String postId = null;
try {
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
postId = graphResponse.getString("id");
}
catch (JSONException e) {
Log.i(app.TAG, "JSON error " + e.getMessage());
}
catch(Exception e){
e.printStackTrace();
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(mContext, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(mContext, postId, Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
else {
toast("no session to publish");
}
}
the session does have publish permissions and it WILL publish a post but all that is there is the "test message" string. The place object is from facebook's servers so it is an actual place with a page_id. When i'm debugging the post params look something like this
Bundle[{message=test message, place=Bundle[{id=171229079554355, location=Bundle[{longitude=-122.434568, latitude=37.797314}], name=The Brixton San Francisco}]}]
Session.openActiveSession(activity, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session != null && session.isOpened()) {
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
activity, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("message", message);
postParams.putString("tags",tag);
postParams.putString("place",place_id);
Request.Callback callback = new Request.Callback() {
private String toastmessage;
public void onCompleted(Response response) {
try {
JSONObject graphResponse = response
.getGraphObject().getInnerJSONObject();
String postId = null;
postId = graphResponse.getString("id");
} catch (Exception e) {
Log.i("Test", "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
isPosted(false);
Toast.makeText(
activity.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
isPosted(true);
toastmessage = "Posted Successfully";
Toast.makeText(activity, toastmessage,
Toast.LENGTH_SHORT).show();
{
}
}
}
};
Request request = new Request(session, "me/feed",
postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
});
这篇关于如何使用android SDK发布支票到Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!