3
  • 我正在为facebook在墙上实现照片发布。在模拟器中运行时它工作正常但在设备中不起作用?
  • 它在设备上显示错误:无效的 android_key 参数。密钥 3x3UBQp16... 与任何允许的密钥不匹配。在http://developers.facebook.com/apps/47775390配置您的应用程序密钥哈希...
  • 我正在尝试使用另一台设备,但它不起作用。
  • 这是我的代码...

    // Facebook

'

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case 32665:
            facebook.authorizeCallback(requestCode, resultCode, data);
        }
        }

        public void onComplete(Bundle values) {

        }

        public void onFacebookError(FacebookError e) {

        }

        public void onError(DialogError e) {

        }

        public void onCancel() {

        }

        public class StartFBupdateStatus extends AsyncTask<Void, Void, String> {
            private String mFacebookToken;

            public StartFBupdateStatus(String mFacebookToken) {
                this.mFacebookToken = mFacebookToken;

            }

            @Override
            protected void onPreExecute() {

                // super.onPreExecute();
                pDialog = ProgressDialog.show(getParent(), "Please wait...",
                        "Photo Uploading on Wall", true, true,
                        new OnCancelListener() {
                            public void onCancel(DialogInterface pd) {
                                try {
                                    pDialog.dismiss();
                                    pDialog = null;
                                    taskFBupdateStatus.cancel(true);
                                } catch (Exception e) {
                                    Log.e("Exception Cought in onCancel:- ",
                                            e.toString());
                                }
                            }
                        });

            }

            @SuppressWarnings("deprecation")
            @Override
            protected String doInBackground(Void... params) {
                String response = null;

                try {

                    Bundle bundle = new Bundle();

                    bundle.putString(Facebook.TOKEN, this.mFacebookToken);
                    // String url = "https://graph.facebook.com/me/photos";
                    // String url = "https://graph.facebook.com/me/";

                    BitmapFactory.Options bounds = new BitmapFactory.Options();
                    bounds.inSampleSize = 1;

                    // ByteArrayOutputStream baos = new ByteArrayOutputStream(
                    // 32 * 1024);

                    if (pDetails.image_path != null) {
                        // byte[] data = null;
                        // Bitmap bmImg;
                        // URL myFileUrl = null;
                        try {
                            // myFileUrl = new URL(product.image);
                            // HttpURLConnection conn = (HttpURLConnection)
                            // myFileUrl
                            // .openConnection();
                            // conn.setDoInput(true);
                            // conn.connect();
                            // InputStream is = conn.getInputStream();
                            //
                            // bmImg = BitmapFactory.decodeStream(is);
                            //
                            // bmImg.compress(Bitmap.CompressFormat.PNG, 100, baos);
                            // data = baos.toByteArray();
                            // Log.v("SATERRA-FACEBOOK",
                            // "IMAGE Byte ARRAY SIZE::"+data.length);
                            bundle.putString("name", product.title);
                            bundle.putString("picture", pDetails.image_path);
                            // bundle.putString("message", "icon please");
                            // bundle.putString("link", "http://www.saterra.com");
                            // bundle.putString("description",
                            // product.short_description);
                            response = facebook.request("me/feed", bundle, "POST");

                            Log.d("UPDATE RESPONSE", "" + response);

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    } else {

                    }
                    // ********* Over Changes *********

                    // try {
                    // baos.close();
                    // } catch (IOException e1) {
                    // Log.d("baos error", e1.toString());
                    // }
                    if (connMgr.getActiveNetworkInfo() != null
                            && connMgr.getActiveNetworkInfo().isAvailable()
                            && connMgr.getActiveNetworkInfo().isConnected()) {
                        try {
                            // response = Util.openUrl(url, "POST", bundle);
                            JSONObject json = Util.parseJson(response);
                            Log.e("Response Photo String", " " + response);
                            handler.post(new Runnable() {
                                public void run() {
                                    Toast.makeText(getParent(),
                                            "Photo Uploaded...", Toast.LENGTH_LONG)
                                            .show();
                                }
                            });
                        } catch (Exception e) {
                            Log.d("Some problem Please try again", e.toString());
                        }
                    } else {
                        handler.post(new Runnable() {
                            public void run() {
                                Toast.makeText(getParent(),
                                        "InternetConnectionNotAvailable",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                    }

                } catch (Exception e) {
                    // Log.e("ProductsDetailActivity",e.getMessage());
                    Log.e("ProductsDetailActivity", e.toString());
                    response = null;
                }

                // String s = facebook.getAccessToken()+"\n";
                // s += String.valueOf(facebook.getAccessExpires())+"\n";
                // s += "Now:"+String.valueOf(System.currentTimeMillis())+"\n";

                return response;
            }

            @Override
            protected void onPostExecute(String result) {
                if (result == null) {
                    Toast toast = Toast.makeText(getParent(), "Facebook Error...",
                            Toast.LENGTH_LONG);
                    // toast.setGravity(Gravity.CENTER, 5, 5);
                    toast.show();
                } else if (result.indexOf("Duplicate status message") > -1) {
                    Toast toast = Toast.makeText(getParent(),
                            "You already said that..", Toast.LENGTH_LONG);
                    // toast.setGravity(Gravity.CENTER, 5, 5);
                    toast.show();
                } else if (result.indexOf("OAuthException") > -1) {
                    Toast toast = Toast.makeText(getParent(), "Facebook Error...",
                            Toast.LENGTH_LONG);
                    // toast.setGravity(Gravity.CENTER, 5, 5);
                    toast.show();
                } else {
                    Toast toast = Toast.makeText(getParent(),
                            "Facebook update sent", Toast.LENGTH_LONG);
                    // toast.setGravity(Gravity.CENTER, 5, 5);
                    toast.show();
                }

                pDialog.dismiss();
            }

        }

        private void fbAuthAndPost() {
            facebook.authorize(getParent(), new String[] { "publish_stream" },
                    new DialogListener() {

                        @Override
                        public void onComplete(Bundle values) {
                            Log.d(this.getClass().getName(),
                                    "Facebook.authorize Complete: ");
                            saveFBToken(facebook.getAccessToken(),
                                    facebook.getAccessExpires());
                            mFacebookToken = facebook.getAccessToken();
                            // updateStatus(values.getString(Facebook.TOKEN),
                            // message);
                            StartFBupdateStatus taskFBupdateStatus = new StartFBupdateStatus(
                                    mFacebookToken);
                            taskFBupdateStatus.execute();
                        }

                        @Override
                        public void onFacebookError(FacebookError error) {
                            Log.d(this.getClass().getName(),
                                    "Facebook.authorize Error: " + error.toString());
                        }

                        @Override
                        public void onError(DialogError e) {
                            Log.d(this.getClass().getName(),
                                    "Facebook.authorize DialogError: "
                                            + e.toString());
                        }

                        @Override
                        public void onCancel() {
                            Log.d(this.getClass().getName(),
                                    "Facebook authorization canceled");
                        }
                    });
        }

        private void saveFBToken(String token, long tokenExpires) {
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(this);
            prefs.edit().putString("FacebookToken", token).commit();
        }
4

0 回答 0