I was trying to use Graph API Post to post an image to FaceBook, I tested it on the Graph Api Explorer with :
link (if you'll test it then replace Page_ID with your page id): Page_ID/photos
JSON :
{
"message": "hello japan",
"transport": "cors",
"url": "https://helpx.adobe.com/content/dam/help/en/photoshop/using/convert-color-image-black-white/jcr_content/main-pars/before_and_after/image-before/Landscape-Color.jpg"
}
and worked as expected.
but now I want to post using my android app using my external/internal storage photos where I only have their Uri while it needs a URL to the image telling me every time
{HttpStatus: 400, errorCode: 1, subErrorCode: -1, errorType: OAuthException, errorMessage: (#1) Could not fetch picture}
so how should I get a URL that represent my Uri that looks like this :
content://media/external/images/media/26281
my code :
private int postRandomData(String photo_uri,String msg, List<PageEntity> pageEntities) {
ArrayList<GraphRequest> requests = new ArrayList<>();
Bundle parameters = new Bundle();
parameters.putString("message",msg);
parameters.putString("url", photo_uri);
GraphRequest.Callback callback = response -> {
if (response.getError() == null) {
//TODO handle error codes
Log.e("response", response.toString());
}
};
for (PageEntity pageEntity : pageEntities) {
AccessToken pageAccessToken = createAccessToken(pageEntity.getPageAccessToken(), pageEntity.getPageId());
requests.add(createPostRequest(callback, pageAccessToken, parameters));
}
GraphRequest.executeBatchAsync(requests)
}
public GraphRequest createPostRequest(GraphRequest.Callback callback, AccessToken accessToken, Bundle parameters) {
GraphRequest request = null;
try {
request = GraphRequest.newPostRequest(accessToken, "/" + accessToken.getUserId() + "/picture", new JSONObject("{}"), callback);
request.setParameters(parameters);
} catch (JSONException exception) {
exception.printStackTrace();
}
return request;
}
public AccessToken createAccessToken(String accessTokenString, String id) {
AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
return new AccessToken(accessTokenString
, currentAccessToken.getApplicationId()
, id
, currentAccessToken.getPermissions()
, currentAccessToken.getDeclinedPermissions()
, currentAccessToken.getExpiredPermissions()
, currentAccessToken.getSource()
, currentAccessToken.getExpires()
, currentAccessToken.getLastRefresh()
, currentAccessToken.getDataAccessExpirationTime());
}