Khawar
Khawar

Reputation: 859

Post picture on facebook wall from drawable/assets android

I've successfully posted image on wall using Uri but now I want to post image from drawable/assets folder, this is what I'm doing.

   Session session = Session.getActiveSession();

    if (session != null){

        // Check for publish permissions    
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            pendingPublishReauthorization = true;
            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }

        PackageManager m = MainTabActivity.this.getPackageManager();
        String s = MainTabActivity.this.getPackageName();

        Uri path = Uri.parse("android.resource://"+s+"/"+R.drawable.app_icon);
        Bundle postParams = new Bundle();
        postParams.putString("message", message+"\n\"App testing (no comments/likes)\"");
        postParams.putString("picture", path.getPath());

        Request.Callback callback= new Request.Callback() {

            public void onCompleted(Response response) {

                String postId = null;
                try 
                {
                    JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                    postId = graphResponse.getString("id");
                } catch (JSONException e) {
                    Log.i(TAG,"JSON error "+ e.getMessage());
                }

                FacebookRequestError error = response.getError();

                if (error != null) 
                    Toast.makeText(getBaseContext(), error.getErrorMessage(),Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(getBaseContext(),  postId,  Toast.LENGTH_LONG).show();         

            }
        };

        Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
    }

// This is how I'm trying to get icon from drawable folder Uri path = Uri.parse("android.resource://"+s+"/"+R.drawable.app_icon);

the callback fetches this result {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) picture URL is not properly formatted}, isFromCache:false}

what I'm doing wrong??

Thanks in advance

Upvotes: 2

Views: 1932

Answers (1)

Ming Li
Ming Li

Reputation: 15662

The "picture" value must be a URL. It cannot be binary data.

Upvotes: 2

Related Questions