如何使用Facebook SDK 4.10到整合Facebook的机器人 [英] how to integrate facebook in android using facebook sdk 4.10
本文介绍了如何使用Facebook SDK 4.10到整合Facebook的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用的登录按钮,在我的XML,我得到的例外,如下面的类不能被实例化: - com.facebook.login.widget.LoginButton(公开课,显示错误日志)我怎么能解决this.and我需要显示的登录页面我怎么能做到这一点。
?这是我的XML
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:以下属性来=@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=com.example.facebooklogin.MainActivity $ PlaceholderFragment>
< com.facebook.login.widget.LoginButton
机器人:ID =@ + ID / login_button
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_horizontal
机器人:layout_marginTop =30dp
机器人:layout_marginBottom =30dp/>
< /相对布局>
解决方案
这是FB SDK的例子是这样的XML code
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:Facebook的=http://schemas.android.com/apk/res-auto
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#FFF
>
<的LinearLayout机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#FFF
机器人:ID =@ + ID / main_ui_container>
< com.facebook.login.widget.LoginButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:layout_gravity =center_horizontal
Facebook的:confirm_logout =假
Facebook的:tooltip_mode =never_display
/>
<的LinearLayout
机器人:layout_width =150dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_horizontal
机器人:重力=center_horizontal
机器人:方向=垂直
>
<的TextView
机器人:ID =@ + ID /问候语
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =10dp
机器人:layout_gravity =中心
机器人:文字颜色=#333
机器人:TEXTSIZE =18sp/>
< com.facebook.login.widget.ProfilePictureView
机器人:ID =@ + ID / profilePicture
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:重力=center_horizontal
机器人:layout_marginBottom =10dp
Facebook的:preset_size =正常/>
<按钮
机器人:ID =@ + ID / postStatusUpdateButton
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=发布状态更新
/>
<按钮
机器人:ID =@ + ID / postPhotoButton
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=后的照片
/>
< / LinearLayout中>
< / LinearLayout中>
< / LinearLayout中>
和Mainfeast文件中像这样
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.facebook.samples.hellofacebook
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =9/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<应用机器人:标签=@字符串/ APP_NAME
机器人:图标=@可绘制/图标
机器人:主题=@安卓风格/ Theme.NoTitleBar
>
<活动机器人:名称=。HelloFacebookSampleActivity
机器人:标签=@字符串/ APP_NAME
机器人:windowSoftInputMode =adjustResize>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:名称=com.facebook.FacebookActivity
机器人:configChanges =键盘| keyboardHidden |屏幕布置|屏幕尺寸|定位
机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar
机器人:标签=@字符串/ APP_NAME/>
<元数据的android:NAME =com.facebook.sdk.ApplicationId机器人:值=@字符串/ APP_ID/>
<元数据的android:NAME =com.facebook.sdk.ApplicationName
机器人:值=@字符串/ facebook_app_name/>
<提供安卓当局=com.facebook.app.FacebookContentProvider355198514515820
机器人:名称=com.facebook.FacebookContentProvider
机器人:出口=真/>
<接收器的Android版本:NAME =com.facebook.samples.hellofacebook.HelloFacebookBroadcastReceiver>
<意向滤光器>
<作用机器人:名称=com.facebook.platform.AppCallResultBroadcast/>
&所述; /意图滤光器>
< /接收器>
< /用途>
< /舱单>
Hi when I am using Login button in my XML, I am getting exception like "The following classes could not be instantiated: - com.facebook.login.widget.LoginButton (Open Class, Show Error Log)". how can I solve this.and I need to display login page how can I do this?
and this is my XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.facebooklogin.MainActivity$PlaceholderFragment" >
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
</Relative Layout>
解决方案
This is xml code of fb sdk example like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:id="@+id/main_ui_container">
<com.facebook.login.widget.LoginButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
facebook:confirm_logout="false"
facebook:tooltip_mode="never_display"
/>
<LinearLayout
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<TextView
android:id="@+id/greeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:textColor="#333"
android:textSize="18sp"/>
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/profilePicture"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:layout_marginBottom="10dp"
facebook:preset_size="normal"/>
<Button
android:id="@+id/postStatusUpdateButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Post Status Update"
/>
<Button
android:id="@+id/postPhotoButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Post Photo"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And Mainfeast file like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.samples.hellofacebook"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:label="@string/app_name"
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar"
>
<activity android:name=".HelloFacebookSampleActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<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/app_id"/>
<meta-data android:name="com.facebook.sdk.ApplicationName"
android:value="@string/facebook_app_name" />
<provider android:authorities="com.facebook.app.FacebookContentProvider355198514515820"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
<receiver android:name="com.facebook.samples.hellofacebook.HelloFacebookBroadcastReceiver">
<intent-filter>
<action android:name="com.facebook.platform.AppCallResultBroadcast" />
</intent-filter>
</receiver>
</application>
</manifest>
这篇关于如何使用Facebook SDK 4.10到整合Facebook的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文