Posts

Showing posts from March, 2015

Making Twitter Media Upload Api work with Java

I was trying to upload an image and do status update on twitter using there api version 1.1. For this I was using media/upload.json  . I was trying to send content of files as base64 encoded string and setting the appropriate content-type and content-transfer-encoding. But this didn't work. I was getting errors like: 1) Missing paramter media 2) Could not authenticate. My main reason to use this approach was I was getting image url and didn't wanted to save it into a file. But this never worked, then I took a different approach of saving the imageurl into a file and doing a multi part upload. Code for it is below. Hope this helps someone. private String uploadImage(String imageUrl) { File f = new File("/tmp/twitterUploadImage_"+StringUtil.encodeURL(imageUrl)); try { FileUtils.copyURLToFile(new URL(imageUrl), f); } catch (IOException e) { logger.severe("Failed to save image in a file"); return null; } U

Making Facebook Graph Photos Api Work with url

As per the documentation on Facebook https://developers.facebook.com/docs/graph-api/reference/v2.2/user/photos/ For /photos api if we want to post a photo to user timeline, using an url on open internet then we must: POST /v2.2/me/photos HTTP/1.1 Host: graph.facebook.com source=%7Bimage-data%7D But this gives: {   "error": {     "message": "An unknown error has occurred.",     "type": "OAuthException",     "code": 1   } } We should avoid adding {} or encode %7B and %7D around image-url for this to work. So correct would be: POST /v2.2/me/photos HTTP/1.1 Host: graph.facebook.com source=image-data

Git CheatSheet/Quickguide

Git Rebase Command git checkout branch name # checkout branch on which you want to merge git rebase branch_name # Original branch would be rebased to current branch. Rebase would remove changes in your branch and merge all the changes from the new branch then applyour changes on top of it. Git merge from a branch. git checkout branch name # checkout branch on which you want to merge git merge branch_name # branch_name is the branch from which you want to merge Reverting merge conflict files git reset --hard HEAD file_name # hard revert to HEAD Reverting to the last commited changes on a branch: git reset --hard HEAD # hard revert to HEAD Switching branches without committing changes: git add uncommited_files # Add uncommitted files to index git stash # Stash your changes git checkout new_branch # Switch to new branch, # Work on the new branch git stash pop # Switch back to