久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Facebook 朋友選擇器 SDK 示例無法在 Android 上運行

Facebook friend picker SDK sample not working Android(Facebook 朋友選擇器 SDK 示例無法在 Android 上運行)
本文介紹了Facebook 朋友選擇器 SDK 示例無法在 Android 上運行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

請幫助我使用 3.14 SDK 從我的個人資料中獲取 facebook 好友.代碼中沒有錯誤,但問題是在我的個人資料中獲取朋友時得到空列表.我在 logcat 中收到錯誤消息
.

Please help me to get the facebook friends from my profile using 3.14 SDK. There is no error in the code but the problem is getting empty list while fetching friends in my profile. I am getting the error in logcat saying
.

05-08 16:18:49.252: E/ActivityThread(25644): Failed to find provider info for com.facebook.orca.provider.PlatformProvider<br>
05-08 16:42:20.453: I/QCNEA(28696): |NIMS| getaddrinfo: hostname graph.facebook.com servname NULL numeric 4 appname <br>
05-08 16:51:32.482: D/Request(31861): Warning: Sessionless Request needs token but missing either application ID or client token<br>

我也在下面生成完整的代碼供您參考

Also i am producing the complete code for your reference below

FriendPickerApplication.java*

package com.facebook.samples.friendpicker;

import android.app.Application;
import com.facebook.model.GraphUser;

import java.util.List;

    // We use a custom Application class to store our minimal state data (which users have been selected).
    // A real-world application will likely require a more robust data model.
    public class FriendPickerApplication extends Application {
        private List<GraphUser> selectedUsers;

        public List<GraphUser> getSelectedUsers() {
            return selectedUsers;
        }

        public void setSelectedUsers(List<GraphUser> selectedUsers) {
            this.selectedUsers = selectedUsers;
        }
    }<br>

FriendPickerSampleActivity.java

package com.facebook.samples.friendpicker;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.AppEventsLogger;
import com.facebook.Session.NewPermissionsRequest;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.Session;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class FriendPickerSampleActivity extends FragmentActivity {
    private static final List<String> PERMISSIONS = new ArrayList<String>() {
        {
            add("user_friends");
            add("public_profile");
        }
    };
    private static final int PICK_FRIENDS_ACTIVITY = 1;
    private Button pickFriendsButton;
    private TextView resultsTextView;
    private UiLifecycleHelper lifecycleHelper;
    boolean pickFriendsWhenSessionOpened;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        resultsTextView = (TextView) findViewById(R.id.resultsTextView);
        pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
        pickFriendsButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                onClickPickFriends();
            }
        });

        lifecycleHelper = new UiLifecycleHelper(this, new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChanged(session, state, exception);
            }
        });
        lifecycleHelper.onCreate(savedInstanceState);

        ensureOpenSession();
    }

    @Override
    protected void onStart() {
        super.onStart();

        // Update the display every time we are started.
        displaySelectedFriends(RESULT_OK);
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Call the 'activateApp' method to log an app event for use in analytics and advertising reporting.  Do so in
        // the onResume methods of the primary Activities that an app may be launched into.
        AppEventsLogger.activateApp(this);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case PICK_FRIENDS_ACTIVITY:
                displaySelectedFriends(resultCode);
                break;
            default:
                Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
                break;
        }
    }

    private boolean ensureOpenSession() {
        if (Session.getActiveSession() == null ||
                !Session.getActiveSession().isOpened()) {
            Session.openActiveSession(
                    this, 
                    true, 
                    PERMISSIONS,
                    new Session.StatusCallback() {
                        @Override
                        public void call(Session session, SessionState state, Exception exception) {
                            onSessionStateChanged(session, state, exception);
                        }
                    });
            return false;
        }
        return true;
    }

    private boolean sessionHasNecessaryPerms(Session session) {
        if (session != null && session.getPermissions() != null) {
            for (String requestedPerm : PERMISSIONS) {
                if (!session.getPermissions().contains(requestedPerm)) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    private List<String> getMissingPermissions(Session session) {
        List<String> missingPerms = new ArrayList<String>(PERMISSIONS);
        if (session != null && session.getPermissions() != null) {
            for (String requestedPerm : PERMISSIONS) {
                if (session.getPermissions().contains(requestedPerm)) {
                    missingPerms.remove(requestedPerm);
                }
            }
        }
        return missingPerms;
    }

    private void onSessionStateChanged(final Session session, SessionState state, Exception exception) {
        if (state.isOpened() && !sessionHasNecessaryPerms(session)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(R.string.need_perms_alert_text);
            builder.setPositiveButton(
                    R.string.need_perms_alert_button_ok, 
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            session.requestNewReadPermissions(
                                    new NewPermissionsRequest(
                                            FriendPickerSampleActivity.this, 
                                            getMissingPermissions(session)));
                        }
                    });
            builder.setNegativeButton(
                    R.string.need_perms_alert_button_quit,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    });
            builder.show();
        } else if (pickFriendsWhenSessionOpened && state.isOpened()) {
            pickFriendsWhenSessionOpened = false;

            startPickFriendsActivity();
        }
    }

    private void displaySelectedFriends(int resultCode) {
        String results = "";
        FriendPickerApplication application = (FriendPickerApplication) getApplication();

        Collection<GraphUser> selection = application.getSelectedUsers();
        if (selection != null && selection.size() > 0) {
            ArrayList<String> names = new ArrayList<String>();
            for (GraphUser user : selection) {
                names.add(user.getName());
            }
            results = TextUtils.join(", ", names);
        } else {
            results = "<No friends selected>";
        }

        resultsTextView.setText(results);
    }

    private void onClickPickFriends() {
        startPickFriendsActivity();
    }

    private void startPickFriendsActivity() {
        if (ensureOpenSession()) {
            Intent intent = new Intent(this, PickFriendsActivity.class);
            // Note: The following line is optional, as multi-select behavior is the default for
            // FriendPickerFragment. It is here to demonstrate how parameters could be passed to the
            // friend picker if single-select functionality was desired, or if a different user ID was
            // desired (for instance, to see friends of a friend).
            PickFriendsActivity.populateParameters(intent, null, true, true);
            startActivityForResult(intent, PICK_FRIENDS_ACTIVITY);
        } else {
            pickFriendsWhenSessionOpened = true;
        }
    }
} <br>

PickFriendsActivity.java

package com.facebook.samples.friendpicker;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.widget.Toast;
import com.facebook.FacebookException;
import com.facebook.model.GraphUser;
import com.facebook.widget.FriendPickerFragment;
import com.facebook.widget.PickerFragment;

import java.util.List;

public class PickFriendsActivity extends FragmentActivity {
    FriendPickerFragment friendPickerFragment;

    public static void populateParameters(Intent intent, String userId,
            boolean multiSelect, boolean showTitleBar) {
        intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY, userId);
        intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY,
                multiSelect);
        intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY,
                showTitleBar);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pick_friends_activity);

        FragmentManager fm = getSupportFragmentManager();

        if (savedInstanceState == null) {
            // First time through, we create our fragment programmatically.
            final Bundle args = getIntent().getExtras();
            friendPickerFragment = new FriendPickerFragment(args);
            fm.beginTransaction()
                    .add(R.id.friend_picker_fragment, friendPickerFragment)
                    .commit();
        } else {
            // Subsequent times, our fragment is recreated by the framework and
            // already has saved and
            // restored its state, so we don't need to specify args again. (In
            // fact, this might be
            // incorrect if the fragment was modified programmatically since it
            // was created.)
            friendPickerFragment = (FriendPickerFragment) fm
                    .findFragmentById(R.id.friend_picker_fragment);
        }

        friendPickerFragment
                .setOnErrorListener(new PickerFragment.OnErrorListener() {
                    @Override
                    public void onError(PickerFragment<?> fragment,
                            FacebookException error) {
                        PickFriendsActivity.this.onError(error);
                    }
                });

        friendPickerFragment
                .setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
                    @Override
                    public void onDoneButtonClicked(PickerFragment<?> fragment) {
                        // We just store our selection in the Application for
                        // other activities to look at.
                        FriendPickerApplication application = (FriendPickerApplication) getApplication();
                        application.setSelectedUsers(friendPickerFragment
                                .getSelection());

                        setResult(RESULT_OK, null);
                        finish();
                    }
                });
    }

    private void onError(Exception error) {
        String text = getString(R.string.exception, error.getMessage());
        Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
        toast.show();
    }

    @Override
    protected void onStart() {
        super.onStart();
        try {
            FriendPickerApplication application = (FriendPickerApplication) getApplication();
            List<GraphUser> selectedUsers = application.getSelectedUsers();
            if (selectedUsers != null && !selectedUsers.isEmpty()) {
                friendPickerFragment.setSelection(selectedUsers);
            }
            // Load data, unless a query has already taken place.
            friendPickerFragment.loadData(false);
        } catch (Exception ex) {
            onError(ex);
        }
    }
}<br>

Androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.facebook.samples.friendpicker"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name=".FriendPickerApplication"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name="FriendPickerSampleActivity"
            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="PickFriendsActivity"
            android:label="Pick Friends" >
        </activity>
        <activity
            android:name="com.facebook.LoginActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

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

        <provider
            android:name="com.facebook.NativeAppCallContentProvider"
            android:authorities="com.facebook.app.NativeAppCallContentProvider1441068969495032"
            android:exported="true" />
    </application>

</manifest>

推薦答案

經(jīng)過長時間的奮斗,我找到了自己解決上述問題的方法.Facebook 最近發(fā)布了他們的新 SDK,以提高安全級別.在您的應(yīng)用中使用 facebook SDK 有一些要求.

After a long struggle I found my own solution to the above question. Facebook have released their new SDK recently to enhance the level of security. There are a few requirements to use facebook SDK in your app.

  1. 應(yīng)用程序應(yīng)發(fā)送提交并需要得到 facebook 的批準(zhǔn)才能在 facebook 內(nèi)使用,以使您自己的應(yīng)用程序能夠顯示 朋友的詳細(xì)信息、訪問位置和其他特殊權(quán)限 審批手續(xù)與 Google Play 應(yīng)用商店類似.

  1. The app should be sent for submission and needs to be approved by facebook to be use inside facebook, to enable your own app to show friends details, access locations and other special permissions The approval formalities are similar to the ones for app store in Google Play.

該應(yīng)用程序必須在 Google Play 中列出,或者您可以將其作為測試用戶進(jìn)行集成(例如 Google Play 中的 beta 測試).

The application must be listed in Google Play, or you may be able to integrate it as a test user (i.e like beta testing in Google Play).

應(yīng)用程序應(yīng)具有正確的包名、啟動活動、域名、網(wǎng)站 url 和電子郵件.

The application should have a proper package name, launching activity, domain name, website url and email.

注冊的app id必須與app namehash key相匹配,必須為在不同的機器

The app id registered must match with an app name and hash key that must be generated for a user developing on different machines

需要添加基本應(yīng)用信息,包括截圖說明應(yīng)用標(biāo)識

The basic application information, including screenshots, description, and app logo needs to be added

成功通過后,您的應(yīng)用名稱旁邊會顯示一個活躍"符號.

Once after the successful approval, an "active" symbol will be displayed near your app name.

我希望這對其他人有用!!!

Facebook 網(wǎng)站上的更多信息.

這篇關(guān)于Facebook 朋友選擇器 SDK 示例無法在 Android 上運行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why would you choose Android API over Google APIs in the SDK on Eclipse?(為什么在 Eclipse 的 SDK 中選擇 Android API 而不是 Google API?)
Couchbase Bucket authentication error(Couchbase 存儲桶身份驗證錯誤)
admob 6.2.1 nullpointer exception(admob 6.2.1 空指針異常)
How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中設(shè)置 SDK?)
My phone cannot be detected in eclipse to test run(eclipse 無法檢測到我的手機進(jìn)行試運行)
platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目錄)
主站蜘蛛池模板: 日韩精品影院 | 日韩一区欧美一区 | 麻豆久久久久 | 国产精品二区三区 | 免费观看的av | 日韩精品成人 | 国产精品久久久久久久久久免费 | 一区二区在线 | 日韩在线中文字幕 | 欧美日韩国产一区二区三区不卡 | 婷婷色在线| 欧美日韩精品一区二区三区四区 | 日韩av在线一区二区 | 欧美中文字幕 | 精品久久久久久久久久久 | 少妇精品亚洲一区二区成人 | 亚洲成av人片在线观看无码 | 九九热免费观看 | 国产精品一区二区在线播放 | 一区二区三区免费 | 羞羞视频网 | 天天干天天插天天 | 亚洲一区国产精品 | 黄色大片网| 成年免费在线观看 | 欧美男人天堂 | 久久av网| 亚洲精品片 | 一级做a爰片性色毛片 | 久草视频观看 | 天天躁日日躁狠狠躁2018小说 | www久久久 | 日韩精品久久久久 | 福利在线观看 | 在线观看视频你懂得 | 久久久久亚洲精品中文字幕 | 中文字幕精品一区二区三区在线 | 久久国产区 | 欧美5区| 精品国产欧美一区二区三区成人 | 91青娱乐在线 |