FacebookSDK接入的那些坑

版权声明:蜜蜂采花酿蜂蜜,奶牛吃草产牛奶。 https://blog.csdn.net/codehxy/article/details/51995777

更加详细的步骤
audience-network接入的步骤和遇到的问题探讨
http://bbs.csdn.net/topics/392021910

1,使用aar代替jar,对Android Studio熟悉的同学建议直接看第4步
1)首先需要开发工具使用Android studio而不是Eclipse;
一个Android studio Module等于一个Eclipse project;
一个Eclipse project等于一个Eclipse workSpace;
2)Android studio中添加依赖
以接入FacebookSDK的原生广告AudienceNetwork为例子,需要依赖DebugSettings.aar和AudienceNetwork.aar
1)放arr包到libs下
AudienceNetwork.aar和DebugSettings.aar放到yourProject/yourModule/libs下面
2)在build.gradle中添加依赖
yourProject/yourModule/build.gradle/dependencies中增加如下配置
这里写图片描述

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile(name: 'AudienceNetwork', ext: 'aar')
    compile(name: 'DebugSettings', ext: 'aar')
  }

3)刷新工程
增加完毕之后,记得点击那个Sync Project with Gradle Files,刷新工程就可以调用FacebookSDK提供的方法了。

2,Add your development and release key hashes
需要获取android studio的release key hashes
最简单的方法:直接采用代码的方式就可以获取;

//Add your development and release key hashes
    public static String printKeyHash(Activity context) {
        PackageInfo packageInfo;
        String key = null;
        try {
            //getting application package name, as defined in manifest
            String packageName = context.getApplicationContext().getPackageName();

            //Retriving package info
            packageInfo = context.getPackageManager().getPackageInfo(packageName,
                    PackageManager.GET_SIGNATURES);

            Log.e("Package Name=", context.getApplicationContext().getPackageName());

            for (Signature signature : packageInfo.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                key = new String(Base64.encode(md.digest(), 0));

                // String key = new String(Base64.encodeBytes(md.digest()));
                Log.e("Key Hash=", key);
            }
        } catch (PackageManager.NameNotFoundException e1) {
            Log.e("Name not found", e1.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.e("No such an algorithm", e.toString());
        } catch (Exception e) {
            Log.e("Exception", e.toString());
        }

        return key;
    }

3,Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider

logcat报错日志

08-04 04:51:31.293: E/ActivityThread(13933): Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
08-04 04:51:32.765: I/linux(13933): onError 1001 No fill. We are not able to serve ads to this person. Please refer to https://developers.facebook.com/docs/audience-network/faq#a12. If you are integrating Audience Network for the first time, you can use test ads https://developers.facebook.com/docs/audience-network/testing.

这个错误出现的原因有哪些?
给应用联网权限;国内要翻墙,测试机要能够连上facebook;安装facebook app并且登录;
我遇到的坑是什么?
没有安装facebook app;不仅仅需要安装,而且还需要登录Facebook APP。
4,aar转换成为jar,Eclipse中怎么使用aar
使用7-zip将aar包解压,里面有个class.jar;直接用这个jar就可以了。
5,参考文档
1)FacebookSDK 广告audiencenetwork对应的文档
https://www.facebook.com/audiencenetwork/docs/android
2)在 Android 应用中添加插播式广告
https://developers.facebook.com/docs/audience-network/android/interstitial/
6,问题求解过程
我是第一接入,最快的方法当然是看开发者文档,遇到错误就google,遇到报错就上stackoverflow;
7,audience-network接入的步骤和遇到的问题探讨
http://bbs.csdn.net/topics/392021910

阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页