简体   繁体   中英

Login to Facebook by Xamarin.Facebook.Android sdk

I want to login to Facebook using my Xamarin android app.

When I build my app it shows following error

在此处输入图片说明

com_facebook_device_auth_dialog_fragment.xml file is below

    <android.support.v7.widget.CardView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" card_view:cardBackgroundColor="@android:color/transparent" 
card_view:cardElevation="10dp" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/com_facebook_auth_dialog_background" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:layout_width="300dp" 
android:layout_height="wrap_content" 
android:background="@drawable/com_facebook_auth_dialog_header_background" 
android:orientation="horizontal">
<FrameLayout android:layout_width="match_parent" 
android:layout_height="wrap_content">
<ImageView android:layout_width="18dp"
 android:layout_height="18dp"
 android:layout_marginBottom="11dp"
 android:layout_marginLeft="12dp"
 android:layout_marginTop="11dp"
 android:adjustViewBounds="false" 
android:scaleType="fitXY" android:src="@drawable/com_facebook_favicon_white" />
</FrameLayout>
<TextView android:id="@+id/com_facebook_device_dialog_title" android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:fontFamily="sans-serif-light"
 android:gravity="center" 
android:text="@string/com_facebook_loginview_log_in_button_long"
 android:textColor="@color/com_facebook_share_button_text_color" 
android:textSize="13sp" android:typeface="sans" />
</RelativeLayout>
<TextView android:id="@+id/com_facebook_device_auth_instructions" 
android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginEnd="16dp"
 android:layout_marginStart="16dp"
 android:layout_marginTop="28dp"
 android:fontFamily="sans-serif-light" 
android:gravity="center_horizontal" 
android:singleLine="false" android:textColor="@color/com_facebook_device_auth_text" 
android:textSize="14sp" 
android:typeface="sans" />
<RelativeLayout android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal"
 android:layout_marginTop="14dp">
<TextView android:id="@+id/confirmation_code" 
android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal"
 android:fontFamily="sans-serif-light" 
android:textColor="@color/com_facebook_device_auth_text" 
android:textSize="23sp"
 android:typeface="sans" 
android:visibility="invisible" />
<ProgressBar android:id="@+id/progress_bar" 
style="@android:style/Widget.Holo.Light.ProgressBar" 
android:layout_width="wrap_content"
 android:layout_height="0dp" 
android:layout_alignBottom="@+id/confirmation_code" 
android:layout_alignTop="@+id/confirmation_code" 
android:layout_centerHorizontal="true" 
android:layout_centerInParent="true"
 android:layout_centerVertical="true" />
</RelativeLayout>
<FrameLayout android:layout_width="match_parent" 
android:layout_height="match_parent"
 android:layout_marginBottom="14dp"
 android:layout_marginTop="17dp">
<Button android:id="@+id/cancel_button"
 android:layout_width="84dp"
 android:layout_height="27dp"
 android:layout_gravity="center_horizontal" 
android:background="@drawable/com_facebook_auth_dialog_cancel_background"
 android:clickable="true"
 android:focusable="true"
 android:fontFamily="sans-serif-medium" 
android:text="@android:string/cancel"
 android:textAllCaps="true" 
android:textColor="@color/com_facebook_device_auth_text" 
android:textSize="10sp"
 android:textStyle="bold"
 android:typeface="sans" />
</FrameLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

I have provided the APP-ID in my string.xml file in this format

<string name="facebook_app_id">APP-ID</string>

My AndroidMainifest.xml file is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="EcoFriend.EcoFriend" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="EcoFriend">
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
</application>

SDKs I have installed are

a) Xamarin.Facebook.Android by Xamarin.Inc. v 4.13.2

b)Xamarin.Android.Support.v4 by Xamarin.Inc v23.4.0.1

c)Xamarin.Android.Support.v7.CardView by Xamarin Inc. v23.4.0.1

d)Bolts by Xamarin.Inc v1.4.0

How to solve this problem?

Just change the:

card_view:cardBackgroundColor="@android:color/transparent" 
card_view:cardElevation="10dp" 

to:

app:cardBackgroundColor="@android:color/transparent" 
app:cardElevation="10dp" 

also add:

xmlns:app="http://schemas.android.com/apk/res-auto"

in

<android.support.v7.widget.CardView...

and you will be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM