Facebook共享会话无法打开错误 [英] Facebook Share session not open error
问题描述
我使用Facebook的SDK从应用程序到用户上传数据的Facebook墙上。
我已经实现了code,允许用户通过一个对话框,共享数据,或者如果用户没有Android的应用程序FB直接在墙壁上张贴,通过教程的 https://developers.facebook.com/docs/android/share 。
我收到以下错误:
无法找到com.facebook.katana.provider.PlatformProvider供应商信息02-19 18:49:28.405:E / AndroidRuntime(12847):致命异常:主要
02-19 18:49:28.405:E / AndroidRuntime(12847):com.facebook.FacebookException:试图使用一个会话没有打开。
。02-19 18:49:28.405:E / AndroidRuntime(12847):在com.facebook.widget.WebDialog $ BuilderBase<&初始化GT;(WebDialog.java:463)
。02-19 18:49:28.405:E / AndroidRuntime(12847):在com.facebook.widget.WebDialog $ FeedDialogBuilder<&初始化GT;(WebDialog.java:626)
02-19 18:49:28.405:E / AndroidRuntime(12847):在com.mooney.diveapp.LogDive.publishFeedDialog(LogDive.java:437)
02-19 18:49:28.405:E / AndroidRuntime(12847):在com.mooney.diveapp.LogDive.onClick(LogDive.java:361)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.view.View.performClick(View.java:4377)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.view.View $ PerformClick.run(View.java:18044)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.os.Handler.handleCallback(Handler.java:725)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.os.Handler.dispatchMessage(Handler.java:92)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.os.Looper.loop(Looper.java:137)
02-19 18:49:28.405:E / AndroidRuntime(12847):在android.app.ActivityThread.main(ActivityThread.java:5306)
02-19 18:49:28.405:E / AndroidRuntime(12847):在java.lang.reflect.Method.invokeNative(本机方法)
02-19 18:49:28.405:E / AndroidRuntime(12847):在java.lang.reflect.Method.invoke(Method.java:511)
02-19 18:49:28.405:E / AndroidRuntime(12847):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-19 18:49:28.405:E / AndroidRuntime(12847):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-19 18:49:28.405:E / AndroidRuntime(12847):在dalvik.system.NativeStart.main(本机方法)
code是:
私人UiLifecycleHelper uiHelper; // FB回调类实例
私人StatusCallback回调;
//的onCreate - FB对象来处理对话框回调
uiHelper =新UiLifecycleHelper(这一点,回调);
uiHelper.onCreate(savedInstanceState);
//调用脸书对话,分享从潜水数据
//首先检查用户的Android应用程序FB,如果不是不能使用对话框andmust利用饲料代替
如果(FacebookDialog.can presentShareDialog(getApplicationContext()
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)){
FacebookDialog shareDialog =新FacebookDialog.ShareDialogBuilder(本)
.setLink(https://developers.facebook.com/android)
.setRequest code(4)
.setApplicationName(潜水应用程序)
.setName(diveSiteString)
.setDescription(this.bottomDiveTime +以分钟的潜水+ this.waterTemperature +
度celcuis,vizibilty+ this.viz +深度
+ this.diveDepth +我评论这下潜一个+ this.diveRate +/ 10!)
.setPlace(this.diveLoctionString)
。建立(); uiHelper.trackPendingDialogCall(shareDialog present());
}其他{
//使用饲料对话框发布的帖子
publishFeedDialog(); }私人无效publishFeedDialog(){
/ *如果不能使用共享对话框,用户dos未haveFB Android应用
*使用Web对话框后饲料
* /
捆绑PARAMS =新包();
params.putString(名,潜水应用程序);
params.putString(标题,潜点+ this.diveSiteString +在+ this.diveLoctionString);
params.putString(说明,this.bottomDiveTime +分钟的潜水在+ this.waterTemperature +
度celcuis,vizibilty+ this.viz +深度
+ this.diveDepth +我评论这一个潜水+ this.diveRate +)/ 5!;
params.putString(链接,https://developers.facebook.com/android);
//params.putString(\"picture,https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png); WebDialog feedDialog =(
新WebDialog.FeedDialogBuilder(getBaseContext()
Session.getActiveSession(),
PARAMS))
.setOnCompleteListener(新OnCompleteListener(){ @覆盖
公共无效的onComplete(束值,
FacebookException错误){
如果(错误== NULL){
//当故事被张贴,呼应成功
//和帖子的ID。
最终字符串postid = values.getString(POST_ID);
如果(帖子ID!= NULL){
Toast.makeText(getBaseContext(),
张贴的故事,ID:+帖子ID,
Toast.LENGTH_SHORT).show();
}其他{
//用户点击了取消按钮
Toast.makeText(getBaseContext()。getApplicationContext(),
发布取消
Toast.LENGTH_SHORT).show();
}
}否则如果(错误的instanceof FacebookOperationCanceledException){
//用户点击X按钮
Toast.makeText(getBaseContext()。getApplicationContext(),
发布取消
Toast.LENGTH_SHORT).show();
}其他{
//通用,例如:网络错误
Toast.makeText(getBaseContext()。getApplicationContext(),
错误张贴的故事
Toast.LENGTH_SHORT).show();
}
} })
。建立();
feedDialog.show(); } //结束publishFeedDialog为FB回调// onActivity结果的方法
保护无效的onActivityResult(INT申请code,INT结果code,
最终意图数据){
//方法检查数据通过startActivityForResult返回表格相机
super.onActivityResult(要求code,结果code,数据);
//检查数据的完整性免受活动类的静态INT
如果(要求code == 4){
//如果REQ code = 4的脸书对话回拨
//配置回调处理时FB分享对话框关闭,且控制返回到应用程序 uiHelper.onActivityResult(要求code,结果code,数据,新FacebookDialog.Callback(){
@覆盖
公共无效onerror的(FacebookDialog.PendingCall pendingCall,异常错误,捆绑数据){
Log.e(活动,的String.format(错误:%s,error.toString()));
} @覆盖
公共无效的onComplete(FacebookDialog.PendingCall pendingCall,捆绑数据){
Log.i(活动,成功!);
}
}); }
确定这样跟着FB上的份额教程,但没有不包括在日志中的会话过程并不在教程清楚。
也配发在网上的教程已经过时(FB SDK版本< 3.6)。
因此,对于那些像我一样开始了这是实现一个非常好的教程最新3.6版2103年12月10日FB SDK:
的http://$c$c2care.org/pages/android-facebook-sdk-3.6-tutorial-integration-with-your-app/
希望有人认为有用的。
I am using the Facebook SDK to upload data from a app to the users Facebook wall.
I have implemented code to allow a user to share data via a dialog box or if user has no android FB app to post directly on wall, went through tutorial https://developers.facebook.com/docs/android/share .
I am getting the following error:
Failed to find provider info for com.facebook.katana.provider.PlatformProvider
02-19 18:49:28.405: E/AndroidRuntime(12847): FATAL EXCEPTION: main
02-19 18:49:28.405: E/AndroidRuntime(12847): com.facebook.FacebookException: Attempted to use a Session that was not open.
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.facebook.widget.WebDialog$BuilderBase.<init>(WebDialog.java:463)
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.facebook.widget.WebDialog$FeedDialogBuilder.<init>(WebDialog.java:626)
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.mooney.diveapp.LogDive.publishFeedDialog(LogDive.java:437)
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.mooney.diveapp.LogDive.onClick(LogDive.java:361)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.view.View.performClick(View.java:4377)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.view.View$PerformClick.run(View.java:18044)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.os.Handler.handleCallback(Handler.java:725)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.os.Looper.loop(Looper.java:137)
02-19 18:49:28.405: E/AndroidRuntime(12847): at android.app.ActivityThread.main(ActivityThread.java:5306)
02-19 18:49:28.405: E/AndroidRuntime(12847): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 18:49:28.405: E/AndroidRuntime(12847): at java.lang.reflect.Method.invoke(Method.java:511)
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-19 18:49:28.405: E/AndroidRuntime(12847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-19 18:49:28.405: E/AndroidRuntime(12847): at dalvik.system.NativeStart.main(Native Method)
Code is:
private UiLifecycleHelper uiHelper;//FB call back class instance
private StatusCallback callback;
//onCreate - FB object to handle dialog callbacks
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
//call face book dialog to share data from dive
//check first if user has android FB app, if not cant use dialog andmust use feed instead
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)){
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setLink("https://developers.facebook.com/android")
.setRequestCode(4)
.setApplicationName("Dive App")
.setName(diveSiteString)
.setDescription(this.bottomDiveTime+" minute dive at "+ this.waterTemperature +
"degrees celcuis, vizibilty "+this.viz+ "depth: "
+this.diveDepth+". I rate this dive a "+this.diveRate+"/5!")
.setPlace(this.diveLoctionString)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}else{
//publish the post using the feed dialog
publishFeedDialog();
}
private void publishFeedDialog() {
/* if cant use share dialog as user dos not haveFB android app
*use a web dialog to post the feed
*/
Bundle params = new Bundle();
params.putString("name", "Dive App");
params.putString("caption", "Dive site "+this.diveSiteString+" at "+this.diveLoctionString);
params.putString("description", this.bottomDiveTime+" minute dive at "+ this.waterTemperature +
"degrees celcuis, vizibilty "+this.viz+ "depth: "
+this.diveDepth+". I rate this dive a "+this.diveRate+"/5!");
params.putString("link", "https://developers.facebook.com/android");
//params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getBaseContext(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getBaseContext(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getBaseContext().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getBaseContext().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getBaseContext().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}//end publishFeedDialog
//onActivity result method for FB callback
protected void onActivityResult(int requestCode, int resultCode,
final Intent data) {
// method checks data returned form camera via startActivityForResult
super.onActivityResult(requestCode, resultCode, data);
// check data integrity against static int from activity class
if(requestCode==4){
//if req code = 4 the face book dialog call back
//configure a callback handler when FB share dialog closes and control returns to app
uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
OK so followed the share tutorial on FB, but didn't not include the log in session process as was not clear on tutorial.
Also allot of tutorials on-line are outdated (FB SDK ver <3.6).
So For those like me starting out this is a very good tutorial for implementing latest version 3.6 Dec 10th 2103 FB SDK:
http://code2care.org/pages/android-facebook-sdk-3.6-tutorial-integration-with-your-app/
Hope someone finds useful.
这篇关于Facebook共享会话无法打开错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!