未显示facebook打开图表对话框

时间:2015-06-04 09:13:38

标签: android facebook facebook-graph-api facebook-opengraph facebook-android-sdk

我正在尝试使用SDK版本4.2.0实现打开的图形对话框。

我更新了我的清单:

 <activity android:name="com.facebook.FacebookActivity"
          android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:label="@string/app_name" />

      <provider android:authorities="com.facebook.app.FacebookContentProvider//My app id//"
          android:name="com.facebook.FacebookContentProvider" 
          android:exported="true" /> 

我在第一个活动中发起了sdk:     FacebookSdk.sdkInitialize(getApplicationContext());

我准备打开的Graph动作和对象:

ShareOpenGraphObject fbRoute = new ShareOpenGraphObject.Builder()
.putString("og:type", "me/objects/fbclimbmystats:route")
.putString("og:title", "")
.putString("name", name)
.putString("grade", grade.getDisplayableGrade(pPrefs, type))
.putString("location", spotName)
.build();   

ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("route.climb")
.putObject("route", fbRoute)
.build();

ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("route")
.setAction(action)
.build();

并显示它:     ShareDialog.show(this,content);

我的问题是甚至没有显示对话框。甚至没有一秒钟,日志猫没有提供太多信息。

其他信息:   - 我还没有经历过在facebook上批准我的应用程序的过程(我无法想象如何做到这一点......)。我应该从那开始吗?

我还想念什么?

谢谢你们。

1 个答案:

答案 0 :(得分:2)

所以我解决了我的问题,这是我的代码,里面有一些经验教训。

我的宣言:

 <activity android:name="com.facebook.FacebookActivity"
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      android:label="@string/app_name" />

    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <meta-data android:name="com.facebook.sdk.ApplicationName"
               android:value="@string/facebook_app_name" />

    <provider android:authorities="com.facebook.app.FacebookContentProvider{facebook_app_id}"
      android:name="com.facebook.FacebookContentProvider" 
      android:exported="true" /> 

生成开放图形对象的代码:

//Create the opengraph object and set the attributes for the route
ShareOpenGraphObject.Builder fbRouteBuilder = new ShareOpenGraphObject.Builder();
fbRouteBuilder.putString("og:type", "fbclimbmystats:route"); // keep the ":"

//The route title 
String fbTitle = name!= null && !name.isEmpty() ? name : "Congrats";
fbRouteBuilder.putString("og:title", fbTitle);

//The route name
if (name!=null && !name.isEmpty())
    fbRouteBuilder.putString("route:name", "le nom");

//the route grade. The route will always have a grade
fbRouteBuilder.putString("route:grade", grade.getDisplayableGrade(pPrefs, type));

//The location will always have a name
fbRouteBuilder.putString("route:location", spotName);

ShareOpenGraphObject fbRoute = fbRouteBuilder.build();  

然后是行动:

//We build the action CLIMB with the Object juste created above
ShareOpenGraphAction.Builder actionBuilder = new ShareOpenGraphAction.Builder();

switch (completion){
case Route.COMPLETION_ON_SIGHT:
    actionBuilder.setActionType("fbclimbmystats:on_sight"); //name space needed
    break;
case Route.COMPLETION_FLASH:
    actionBuilder.setActionType("fbclimbmystats:flash");
    break;
default :
    actionBuilder.setActionType("fbclimbmystats:climb");
}

actionBuilder.putObject("route", fbRoute); 
ShareOpenGraphAction action = actionBuilder.build();

最后是内容对象:

ShareOpenGraphContent.Builder contentBuilder = new ShareOpenGraphContent.Builder();
    contentBuilder.setPreviewPropertyName("route"); // No namespace here
    contentBuilder.setAction(action);
    ShareOpenGraphContent content =  contentBuilder.build();

以下是通过反复试验获得的一些知识:

  • 如果未在图表中的句子中使用属性,请不要提供属性。
  • 不要提供空属性(传递空字符串)
  • 属性“namespace.object”不正确。始终使用“namespace:object”
  • 对于对象的自定义属性,请使用“object:attribute”
  • 调用它们