Facebook与android的集成不起作用
我关注了这张脸书。。用于集成,但我的应用程序显示空白活动。当我运行我的应用程序时,Facebook登录按钮不显示 我已使用密钥和应用程序Id向developer.facebook.com注册了完整的应用程序 然后我必须执行以下代码 AndroidMenifest.xmlFacebook与android的集成不起作用,android,facebook,facebook-login,Android,Facebook,Facebook Login,我关注了这张脸书。。用于集成,但我的应用程序显示空白活动。当我运行我的应用程序时,Facebook登录按钮不显示 我已使用密钥和应用程序Id向developer.facebook.com注册了完整的应用程序 然后我必须执行以下代码 AndroidMenifest.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/an
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:layout="@layout/fragment_simple_login_button"
android:layout_width="match_parent"
android:layout_height="match_parent">
}
FragmentSimpleLoginButton
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".FragmentSimpleLoginButton">
<TextView
android:id="@+id/text_details"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/login_button" />
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
public class FragmentSimpleLoginButton extends Fragment {
private TextView mTextDetails;
private CallbackManager mCallbackManager;
private AccessTokenTracker mTokenTracker;
private ProfileTracker mProfileTracker;
private FacebookCallback<LoginResult> mFacebookCallback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("Vvvvvvv", "onSuccess");
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
mTextDetails.setText(constructWelcomeMessage(profile));
}
@Override
public void onCancel() {
Log.d("Vvvvvvvv", "onCancel");
}
@Override
public void onError(FacebookException e) {
Log.d("Vvvvvvvv", "onError " + e);
}
};
public FragmentSimpleLoginButton() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCallbackManager = CallbackManager.Factory.create();
setupTokenTracker();
setupProfileTracker();
mTokenTracker.startTracking();
mProfileTracker.startTracking();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_simple_login_button, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
setupTextDetails(view);
setupLoginButton(view);
}
@Override
public void onResume() {
super.onResume();
Profile profile = Profile.getCurrentProfile();
mTextDetails.setText(constructWelcomeMessage(profile));
}
@Override
public void onStop() {
super.onStop();
mTokenTracker.stopTracking();
mProfileTracker.stopTracking();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
private void setupTextDetails(View view) {
mTextDetails = (TextView) view.findViewById(R.id.text_details);
}
private void setupTokenTracker() {
mTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
Log.d("Vvvvvvv", "" + currentAccessToken);
}
};
}
private void setupProfileTracker() {
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
Log.d("Vvvvvvvv", "" + currentProfile);
mTextDetails.setText(constructWelcomeMessage(currentProfile));
}
};
}
private void setupLoginButton(View view) {
LoginButton mButtonLogin = (LoginButton) view.findViewById(R.id.login_button);
mButtonLogin.setFragment(this);
mButtonLogin.setReadPermissions("user_friends");
mButtonLogin.registerCallback(mCallbackManager, mFacebookCallback);
}
private String constructWelcomeMessage(Profile profile) {
StringBuffer stringBuffer = new StringBuffer();
if (profile != null) {
stringBuffer.append("Welcome " + profile.getName());
}
return stringBuffer.toString();
}
公共类片段SimpleLoginButton扩展片段{
私有文本查看mTextDetails;
私有CallbackManager-mCallbackManager;
私有访问令牌跟踪程序mTokenTracker;
私人档案跟踪器mProfileTracker;
私有FacebookCallback mFacebookCallback=新FacebookCallback(){
@凌驾
成功时公共无效(LoginResult LoginResult){
Log.d(“vvv”、“onSuccess”);
AccessToken AccessToken=loginResult.getAccessToken();
Profile Profile=Profile.getCurrentProfile();
setText(constructWelcomeMessage(profile));
}
@凌驾
公开作废{
Log.d(“vv”、“onCancel”);
}
@凌驾
公共无效onError(FaceBook例外e){
日志d(“VV”、“onError”+e);
}
};
公共碎片SimpleLoginButton(){
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mCallbackManager=CallbackManager.Factory.create();
setupTokenTracker();
setupProfileTracker();
mTokenTracker.startTracking();
mProfileTracker.startTracking();
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
返回充气机。充气(R.layout.fragment\u simple\u login\u按钮,容器,false);
}
@凌驾
已创建视图上的公共void(视图,捆绑保存状态){
setupTextDetails(视图);
设置登录按钮(视图);
}
@凌驾
恢复时公开作废(){
super.onResume();
Profile Profile=Profile.getCurrentProfile();
setText(constructWelcomeMessage(profile));
}
@凌驾
公共void onStop(){
super.onStop();
mTokenTracker.stopTracking();
mProfileTracker.stopTracking();
}
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
onActivityResult(请求代码、结果代码、数据);
}
私有void setupTextDetails(视图){
mTextDetails=(TextView)view.findViewById(R.id.text\u details);
}
私有void setupTokenTracker(){
mTokenTracker=new AccessTokenTracker(){
@凌驾
受保护的onCurrentAccessTokenChanged无效(AccessToken oldAccessToken、AccessToken currentAccessToken){
Log.d(“VVV”,即“+currentAccessToken”);
}
};
}
私有void setupProfileTracker(){
mProfileTracker=newprofiletracker(){
@凌驾
更改当前配置文件时受保护的无效(配置文件oldProfile、配置文件currentProfile){
Log.d(“VV”和“+currentProfile”);
setText(constructWelcomeMessage(currentProfile));
}
};
}
私有void设置登录按钮(视图){
LoginButton mButtonLogin=(LoginButton)view.findViewById(R.id.login_按钮);
mButtonLogin.setFragment(本);
mButtonLogin.setReadPermissions(“用户朋友”);
mButtonLogin.registerCallback(mCallbackManager,mFacebookCallback);
}
私有字符串消息(配置文件){
StringBuffer StringBuffer=新的StringBuffer();
if(profile!=null){
追加(“欢迎”+profile.getName());
}
返回stringBuffer.toString();
}
}
请帮帮我。。。
谢谢大家! 一切正常,但您在活动中错过了FB按钮。为什么不添加以下代码
<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" />
这些权限在清单文件中是必需的,例如,您没有在清单文件中指定
提供程序,因此,请查看下面的示例,并在您的末尾更正它:-
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />///provide yours fb id here
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider16554302080646"//// PROVIDE YOURS IDS HERE
android:exported="true" />
///请在此处提供您的fb id
我已经用我的应用程序id添加了这个提供商标签,但当我运行应用程序时,它仍然显示空白活动,没有facebook按钮。@VandanaRao。。你是否在“android:Authories”结尾给出了正确的facebook id?…首先检查一下我已经这样添加了它。。。。。。。android:authorities=“com.facebook.app.FacebookContentProvider539236509587640”您想要执行什么功能…只是共享消息吗?我这样做只是为了学习,所以我有一个用于fb集成的演示…请帮助我
<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" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />///provide yours fb id here
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider16554302080646"//// PROVIDE YOURS IDS HERE
android:exported="true" />