{"action":"created","comment":{"url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/comments/88713580","pull_request_review_id":9280832,"id":88713580,"diff_hunk":"@@ -0,0 +1,178 @@\n+package net.serkanbal.oathlab_twitter;\n+\n+import android.os.Bundle;\n+import android.support.v7.app.AppCompatActivity;\n+import android.support.v7.widget.LinearLayoutManager;\n+import android.support.v7.widget.RecyclerView;\n+import android.util.Log;\n+import android.view.View;\n+import android.widget.Button;\n+import android.widget.EditText;\n+\n+import com.google.gson.Gson;\n+\n+import org.apache.commons.codec.binary.Base64;\n+\n+import java.io.IOException;\n+import java.io.UnsupportedEncodingException;\n+import java.net.URLEncoder;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import okhttp3.Call;\n+import okhttp3.Callback;\n+import okhttp3.FormBody;\n+import okhttp3.OkHttpClient;\n+import okhttp3.Request;\n+import okhttp3.RequestBody;\n+import okhttp3.Response;\n+\n+public class MainActivity extends AppCompatActivity {\n+    public static final String CONSUMER_KEY = \"gKOs6rrJhWoH73ZHTjyy33QFH\";\n+    public static final String CONSUMER_SECRET = \"0LF56WARaf02v1KilCfBnpCZAsG2HBAnPAdLQu377FO7BA7vVn\";\n+    public String mScreenName = \"MargotRobbie\";\n+    List<TwitterObject> mList = new ArrayList<>();\n+    EditText mScreenNameEntry;\n+    Button mSearch;\n+\n+    @Override\n+    protected void onCreate(Bundle savedInstanceState) {\n+        super.onCreate(savedInstanceState);\n+        setContentView(R.layout.activity_main);\n+\n+        getBearerToken(encodeKeys(CONSUMER_KEY, CONSUMER_SECRET));\n+\n+        mSearch = (Button) findViewById(R.id.search_button);\n+        mScreenNameEntry = (EditText) findViewById(R.id.search_query);\n+\n+        mSearch.setOnClickListener(new View.OnClickListener() {\n+            @Override\n+            public void onClick(View view) {\n+                mScreenName = mScreenNameEntry.getText().toString();\n+                getBearerToken(encodeKeys(CONSUMER_KEY, CONSUMER_SECRET));\n+            }\n+        });\n+\n+    }\n+\n+\n+    // Encodes the consumer key and secret to create the basic authorization key\n+    private String encodeKeys(String consumerKey, String consumerSecret) {\n+        try {\n+            String encodedConsumerKey = URLEncoder.encode(consumerKey, \"UTF-8\");\n+            String encodedConsumerSecret = URLEncoder.encode(consumerSecret, \"UTF-8\");\n+\n+            String fullKey = encodedConsumerKey + \":\" + encodedConsumerSecret;\n+            byte[] encodedBytes = Base64.encodeBase64(fullKey.getBytes());\n+            return new String(encodedBytes);\n+        }\n+        catch (UnsupportedEncodingException e) {\n+            return null;\n+        }\n+    }\n+\n+    public void getBearerToken(String encoded) {\n+        OkHttpClient client = new OkHttpClient();\n+\n+        RequestBody requestBody = new FormBody.Builder()\n+                .add(\"grant_type\", \"client_credentials\")\n+                .build();\n+\n+        final Request request = new Request.Builder()\n+                .addHeader(\"Authorization\", \"Basic \" + encoded)\n+                .addHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\")\n+                .post(requestBody)\n+                .url(\"https://api.twitter.com/oauth2/token\")\n+                .build();\n+\n+        client.newCall(request).enqueue(new Callback() {\n+            @Override\n+            public void onFailure(Call call, IOException e) {\n+                e.printStackTrace();\n+            }\n+\n+            @Override\n+            public void onResponse(Call call, Response response) throws IOException {\n+                if (!response.isSuccessful()) {\n+                    throw new IOException(\"on Response \" + response);\n+                } else {\n+                    String data = response.body().string();\n+\n+                    Gson gson = new Gson();\n+                    BearerToken bearer = gson.fromJson(data, BearerToken.class);\n+                    String bearerToken = bearer.getBearerToken();\n+\n+//                        JSONObject obj = new JSONObject(response.body().string());\n+//                        String bearerToken = obj.getString(\"access_token\");\n+                    Log.d(\"Access_Token\", \"Your Access Token is: \" + bearerToken);\n+\n+                    getTweets(bearerToken, mScreenName);\n+\n+                }\n+            }\n+        });\n+    }\n+\n+    private void getTweets(String bearerToken, String screenName) {\n+        OkHttpClient client = new OkHttpClient();\n+\n+        Request request = new Request.Builder()\n+                .addHeader(\"Authorization\", \"Bearer \" + bearerToken)\n+                .url(\"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=\" +","path":"OathLab_Twitter/app/src/main/java/net/serkanbal/oathlab_twitter/MainActivity.java","position":121,"original_position":121,"commit_id":"e086f82b708415e22bddad3a5ff633d9981a5323","original_commit_id":"e086f82b708415e22bddad3a5ff633d9981a5323","user":{"login":"charlesdrews","id":6901943,"avatar_url":"https://avatars.githubusercontent.com/u/6901943?v=3","gravatar_id":"","url":"https://api.github.com/users/charlesdrews","html_url":"https://github.com/charlesdrews","followers_url":"https://api.github.com/users/charlesdrews/followers","following_url":"https://api.github.com/users/charlesdrews/following{/other_user}","gists_url":"https://api.github.com/users/charlesdrews/gists{/gist_id}","starred_url":"https://api.github.com/users/charlesdrews/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charlesdrews/subscriptions","organizations_url":"https://api.github.com/users/charlesdrews/orgs","repos_url":"https://api.github.com/users/charlesdrews/repos","events_url":"https://api.github.com/users/charlesdrews/events{/privacy}","received_events_url":"https://api.github.com/users/charlesdrews/received_events","type":"User","site_admin":false},"body":"Might be helpful to put this url in a constant at the top of the class so it's easier to find","created_at":"2016-11-18T18:39:40Z","updated_at":"2016-11-18T18:39:40Z","html_url":"https://github.com/ga-adi-macaron/oauth-lab/pull/3#discussion_r88713580","pull_request_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/comments/88713580"},"html":{"href":"https://github.com/ga-adi-macaron/oauth-lab/pull/3#discussion_r88713580"},"pull_request":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3","id":94290802,"html_url":"https://github.com/ga-adi-macaron/oauth-lab/pull/3","diff_url":"https://github.com/ga-adi-macaron/oauth-lab/pull/3.diff","patch_url":"https://github.com/ga-adi-macaron/oauth-lab/pull/3.patch","issue_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/3","number":3,"state":"open","locked":false,"title":"Serkan - Oath Lab Done","user":{"login":"serkanbal","id":20479798,"avatar_url":"https://avatars.githubusercontent.com/u/20479798?v=3","gravatar_id":"","url":"https://api.github.com/users/serkanbal","html_url":"https://github.com/serkanbal","followers_url":"https://api.github.com/users/serkanbal/followers","following_url":"https://api.github.com/users/serkanbal/following{/other_user}","gists_url":"https://api.github.com/users/serkanbal/gists{/gist_id}","starred_url":"https://api.github.com/users/serkanbal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serkanbal/subscriptions","organizations_url":"https://api.github.com/users/serkanbal/orgs","repos_url":"https://api.github.com/users/serkanbal/repos","events_url":"https://api.github.com/users/serkanbal/events{/privacy}","received_events_url":"https://api.github.com/users/serkanbal/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-18T02:13:27Z","updated_at":"2016-11-18T18:41:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b2ec4b5dbf08371cc4aec9254906e0130d3bc80","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3/commits","review_comments_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3/comments","review_comment_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/3/comments","statuses_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/statuses/e086f82b708415e22bddad3a5ff633d9981a5323","head":{"label":"serkanbal:master","ref":"master","sha":"e086f82b708415e22bddad3a5ff633d9981a5323","user":{"login":"serkanbal","id":20479798,"avatar_url":"https://avatars.githubusercontent.com/u/20479798?v=3","gravatar_id":"","url":"https://api.github.com/users/serkanbal","html_url":"https://github.com/serkanbal","followers_url":"https://api.github.com/users/serkanbal/followers","following_url":"https://api.github.com/users/serkanbal/following{/other_user}","gists_url":"https://api.github.com/users/serkanbal/gists{/gist_id}","starred_url":"https://api.github.com/users/serkanbal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serkanbal/subscriptions","organizations_url":"https://api.github.com/users/serkanbal/orgs","repos_url":"https://api.github.com/users/serkanbal/repos","events_url":"https://api.github.com/users/serkanbal/events{/privacy}","received_events_url":"https://api.github.com/users/serkanbal/received_events","type":"User","site_admin":false},"repo":{"id":74068102,"name":"oauth-lab","full_name":"serkanbal/oauth-lab","owner":{"login":"serkanbal","id":20479798,"avatar_url":"https://avatars.githubusercontent.com/u/20479798?v=3","gravatar_id":"","url":"https://api.github.com/users/serkanbal","html_url":"https://github.com/serkanbal","followers_url":"https://api.github.com/users/serkanbal/followers","following_url":"https://api.github.com/users/serkanbal/following{/other_user}","gists_url":"https://api.github.com/users/serkanbal/gists{/gist_id}","starred_url":"https://api.github.com/users/serkanbal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serkanbal/subscriptions","organizations_url":"https://api.github.com/users/serkanbal/orgs","repos_url":"https://api.github.com/users/serkanbal/repos","events_url":"https://api.github.com/users/serkanbal/events{/privacy}","received_events_url":"https://api.github.com/users/serkanbal/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/serkanbal/oauth-lab","description":null,"fork":true,"url":"https://api.github.com/repos/serkanbal/oauth-lab","forks_url":"https://api.github.com/repos/serkanbal/oauth-lab/forks","keys_url":"https://api.github.com/repos/serkanbal/oauth-lab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serkanbal/oauth-lab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serkanbal/oauth-lab/teams","hooks_url":"https://api.github.com/repos/serkanbal/oauth-lab/hooks","issue_events_url":"https://api.github.com/repos/serkanbal/oauth-lab/issues/events{/number}","events_url":"https://api.github.com/repos/serkanbal/oauth-lab/events","assignees_url":"https://api.github.com/repos/serkanbal/oauth-lab/assignees{/user}","branches_url":"https://api.github.com/repos/serkanbal/oauth-lab/branches{/branch}","tags_url":"https://api.github.com/repos/serkanbal/oauth-lab/tags","blobs_url":"https://api.github.com/repos/serkanbal/oauth-lab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serkanbal/oauth-lab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serkanbal/oauth-lab/git/refs{/sha}","trees_url":"https://api.github.com/repos/serkanbal/oauth-lab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serkanbal/oauth-lab/statuses/{sha}","languages_url":"https://api.github.com/repos/serkanbal/oauth-lab/languages","stargazers_url":"https://api.github.com/repos/serkanbal/oauth-lab/stargazers","contributors_url":"https://api.github.com/repos/serkanbal/oauth-lab/contributors","subscribers_url":"https://api.github.com/repos/serkanbal/oauth-lab/subscribers","subscription_url":"https://api.github.com/repos/serkanbal/oauth-lab/subscription","commits_url":"https://api.github.com/repos/serkanbal/oauth-lab/commits{/sha}","git_commits_url":"https://api.github.com/repos/serkanbal/oauth-lab/git/commits{/sha}","comments_url":"https://api.github.com/repos/serkanbal/oauth-lab/comments{/number}","issue_comment_url":"https://api.github.com/repos/serkanbal/oauth-lab/issues/comments{/number}","contents_url":"https://api.github.com/repos/serkanbal/oauth-lab/contents/{+path}","compare_url":"https://api.github.com/repos/serkanbal/oauth-lab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serkanbal/oauth-lab/merges","archive_url":"https://api.github.com/repos/serkanbal/oauth-lab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serkanbal/oauth-lab/downloads","issues_url":"https://api.github.com/repos/serkanbal/oauth-lab/issues{/number}","pulls_url":"https://api.github.com/repos/serkanbal/oauth-lab/pulls{/number}","milestones_url":"https://api.github.com/repos/serkanbal/oauth-lab/milestones{/number}","notifications_url":"https://api.github.com/repos/serkanbal/oauth-lab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serkanbal/oauth-lab/labels{/name}","releases_url":"https://api.github.com/repos/serkanbal/oauth-lab/releases{/id}","deployments_url":"https://api.github.com/repos/serkanbal/oauth-lab/deployments","created_at":"2016-11-17T21:15:23Z","updated_at":"2016-11-18T02:13:10Z","pushed_at":"2016-11-18T03:51:10Z","git_url":"git://github.com/serkanbal/oauth-lab.git","ssh_url":"git@github.com:serkanbal/oauth-lab.git","clone_url":"https://github.com/serkanbal/oauth-lab.git","svn_url":"https://github.com/serkanbal/oauth-lab","homepage":null,"size":259,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ga-adi-macaron:master","ref":"master","sha":"f3c275eb7fccdca347e0e0a3c74dc6dac17e62b3","user":{"login":"ga-adi-macaron","id":22455948,"avatar_url":"https://avatars.githubusercontent.com/u/22455948?v=3","gravatar_id":"","url":"https://api.github.com/users/ga-adi-macaron","html_url":"https://github.com/ga-adi-macaron","followers_url":"https://api.github.com/users/ga-adi-macaron/followers","following_url":"https://api.github.com/users/ga-adi-macaron/following{/other_user}","gists_url":"https://api.github.com/users/ga-adi-macaron/gists{/gist_id}","starred_url":"https://api.github.com/users/ga-adi-macaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ga-adi-macaron/subscriptions","organizations_url":"https://api.github.com/users/ga-adi-macaron/orgs","repos_url":"https://api.github.com/users/ga-adi-macaron/repos","events_url":"https://api.github.com/users/ga-adi-macaron/events{/privacy}","received_events_url":"https://api.github.com/users/ga-adi-macaron/received_events","type":"Organization","site_admin":false},"repo":{"id":74050206,"name":"oauth-lab","full_name":"ga-adi-macaron/oauth-lab","owner":{"login":"ga-adi-macaron","id":22455948,"avatar_url":"https://avatars.githubusercontent.com/u/22455948?v=3","gravatar_id":"","url":"https://api.github.com/users/ga-adi-macaron","html_url":"https://github.com/ga-adi-macaron","followers_url":"https://api.github.com/users/ga-adi-macaron/followers","following_url":"https://api.github.com/users/ga-adi-macaron/following{/other_user}","gists_url":"https://api.github.com/users/ga-adi-macaron/gists{/gist_id}","starred_url":"https://api.github.com/users/ga-adi-macaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ga-adi-macaron/subscriptions","organizations_url":"https://api.github.com/users/ga-adi-macaron/orgs","repos_url":"https://api.github.com/users/ga-adi-macaron/repos","events_url":"https://api.github.com/users/ga-adi-macaron/events{/privacy}","received_events_url":"https://api.github.com/users/ga-adi-macaron/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ga-adi-macaron/oauth-lab","description":null,"fork":false,"url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab","forks_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/forks","keys_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/teams","hooks_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/hooks","issue_events_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/events{/number}","events_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/events","assignees_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/assignees{/user}","branches_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/branches{/branch}","tags_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/tags","blobs_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/git/refs{/sha}","trees_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/statuses/{sha}","languages_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/languages","stargazers_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/stargazers","contributors_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/contributors","subscribers_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/subscribers","subscription_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/subscription","commits_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/commits{/sha}","git_commits_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/git/commits{/sha}","comments_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/comments{/number}","issue_comment_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/comments{/number}","contents_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/contents/{+path}","compare_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/merges","archive_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/downloads","issues_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues{/number}","pulls_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls{/number}","milestones_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/milestones{/number}","notifications_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/labels{/name}","releases_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/releases{/id}","deployments_url":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/deployments","created_at":"2016-11-17T17:20:15Z","updated_at":"2016-11-18T16:38:24Z","pushed_at":"2016-11-18T17:27:04Z","git_url":"git://github.com/ga-adi-macaron/oauth-lab.git","ssh_url":"git@github.com:ga-adi-macaron/oauth-lab.git","clone_url":"https://github.com/ga-adi-macaron/oauth-lab.git","svn_url":"https://github.com/ga-adi-macaron/oauth-lab","homepage":null,"size":349,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":5,"forks":10,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3"},"html":{"href":"https://github.com/ga-adi-macaron/oauth-lab/pull/3"},"issue":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/3"},"comments":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/ga-adi-macaron/oauth-lab/statuses/e086f82b708415e22bddad3a5ff633d9981a5323"}}}}
{"actor":{"display_login":"charlesdrews"}}