我正在使用Facebook SDK将数据从应用程序上传到用户Facebook墙。
我已经实现了允许用户通过对话框共享数据的代码,或者如果用户没有直接在墙上发布的android FB应用程序,则通过教程https://developers.facebook.com/docs/android/share。
我收到以下错误:
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)
代码是:
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!");
}
});
}
答案 0 :(得分:3)
确定如此遵循FB上的共享教程,但没有包含登录会话过程,因为在教程中并不清楚。
在线分配的教程也已过时(FB SDK ver&lt; 3.6)。
所以对于像我这样的人来说,这是一个非常好的教程,用于实现最新版本3.6 Dec 10th 2103 FB SDK:
http://code2care.org/pages/android-facebook-sdk-3.6-tutorial-integration-with-your-app/
希望有人觉得有用。
答案 1 :(得分:1)
您必须在applicationId
中定义AndroidManifest.xml
像这样:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
其中<application android:label="@string/app_name"....
是app_id
中的字符串。