{"id":561,"date":"2011-10-08T15:49:01","date_gmt":"2011-10-08T07:49:01","guid":{"rendered":"http:\/\/zduo.me\/blog\/?p=561"},"modified":"2011-10-24T12:55:35","modified_gmt":"2011-10-24T04:55:35","slug":"%e4%bd%bf%e7%94%a8google%e5%b8%b3%e6%88%b6%e7%99%bb%e9%8c%84%ef%bc%88oauth%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"http:\/\/zduo.me\/blog\/?p=561","title":{"rendered":"\u4f7f\u7528Google\u8d26\u6237\u767b\u9646\uff08Oauth\u7248\uff09"},"content":{"rendered":"<p>\u9996\u5148\u8981\u7533\u8bf7CONSUMER_KEY\u548cCONSUMER_SECRET\uff0c\u7533\u8bf7\u5730\u5740:https:\/\/www.google.com\/accounts\/ManageDomains<\/p>\n<p>OAuth\u9a8c\u8bc1\u7b2c\u4e00\u6b65:Get a Request Token.<br \/>\n\u8fd9\u4e2aRequest Token\u662f\u8bf7\u6c42\u4e00\u4e2a\u4ee4\u724c\uff0c\u6765\u5141\u8bb8\u7a0b\u5e8f\u63a5\u5165google\u7684\u670d\u52a1\u3002\u5177\u4f53\u505a\u6cd5\u662f\u53d1\u9001\u4e00\u4e2aHTTP GET\u8bf7\u6c42\u5230https:\/\/www.google.com\/accounts\/OAuthGetRequestToken,\u5e76\u4e14\u5728HTTP\u5934\u91cc\u6709\u4e00\u4e2aAuthorization\u5b57\u6bb5\uff0c\u5b57\u6bb5\u91cc\u7684\u5185\u5bb9\u662fOAuth\u5f00\u5934\uff0c\u52a0\u4e00\u4e2a\u7a7a\u683c\uff0c\u7136\u540e\u662f\u6bcf\u4e2a\u53c2\u6570join\u4e00\u4e2a\u201c,\u201d\u548c\u7a7a\u683c\u3002\u6b64\u5916google\u7684OAuth\u8fd8\u6709\u4e00\u4e2aSCOPE\u53c2\u6570\uff0c\u8fd9\u4e2a\u4e0d\u662f\u6807\u51c6OAuth\u91cc\u7684\u3002<br \/>\n\u6700\u540e\u6ce8\u610f\u7aef\u53e3\u662f443\uff0c\u4e0d\u7136\u4f1a\u6536\u5230\u4e00\u4e2a302;\u5982\u679c\u7a0b\u5e8f\u6709\u95ee\u9898\u4f1a\u6536\u5230\u4e00\u4e2a400\u3002\u5982\u679c\u662f200\uff0c\u5219\u5728\u8fd4\u56de\u7684HTTP BODY\u91cc\u53d6\u5f97$oauth_token,$oauth_token_secret\u4fdd\u5b58\u597d\u8fd9\u4e24\u4e2a\u503c\uff0c\u4e0b\u4e24\u6b65\u8981\u7528\u5230\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65\u662f\u7528\u6237\u64cd\u4f5c\u90e8\u5206\uff0c\u9700\u8981\u7528\u6237\u6388\u6743\u5e94\u7528\u8bbf\u95eeGOOGLE\u76f8\u5173\u670d\u52a1\u3002<br \/>\n\u4e5f\u5c31\u662fredirect\u5230 www.google.com\/accounts\/OAuthAuthorizeToken?oauth_token=\u521a\u624d\u7684KEY\uff0c\u83b7\u53d6\u7528\u6237\u8054\u7cfb\u4eba\u5217\u8868\u7684scope\u662fhttps:\/\/www.google.com\/m8\/feeds\/\uff0c\u7528\u6237\u5141\u8bb8Access\u540e\u5c31\u4f1a\u8df3\u8f6c\u56de\u521a\u624d\u7684\u9875\u9762\uff0c\u5e76\u4e14\u5728URL\u53c2\u6570\u91cc\u591a\u4e86\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65\u662f\u51ed\u521a\u624dURL\u91cc\u9a8c\u8bc1\u7684\u53c2\u6570\u53d1\u9001\u4e00\u4e2aGET\u8bf7\u6c42\u5230https:\/\/www.google.com\/accounts\/OAuthGetAccessToken,\u83b7\u53d6\u63a5\u5165GOOGLE\u670d\u52a1\u7684\u6743\u9650\uff0cHEADER\u91cc\u4ecd\u65e7\u8981\u5305\u542bAuthorization\u5b57\u6bb5\u3002\u5f97\u5230KEY\u548cSECRET\u540e\u66ff\u6362\u521a\u624d\u4e00\u5f00\u59cb\u7684KEY\u548cSECRET\uff0c\u53d1\u9001GET\u8bf7\u6c42\u5230 \u83b7\u53d6\u7528\u6237\u8054\u7cfb\u4eba\u7684scope\uff08https:\/\/www.google.com\/m8\/feeds\/contacts\/default\/thin\uff09\uff0cmax-results\u53c2\u6570\u4ee3\u8868\u83b7\u53d6\u8054\u7cfb\u4eba\u7684\u4e2a\u6570\uff0c\u8fd4\u56de\u7684XML\u5305\u542b&lt;id&gt;\u4e3a\u90ae\u7bb1\uff0c&lt;title&gt;\u91cc\u9762\u542b\u6709\u7528\u6237\u540d\uff0c\u5176\u4e2d\u7b2c\u4e00\u6761\u8bb0\u5f55\u5c31\u662f\u7528\u6237\u672c\u4eba\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u8be6\u7ec6\u7684\u6280\u672f\u6587\u6863\u5728\u8fd9\u91cc http:\/\/code.google.com\/apis\/accounts\/docs\/OAuth_ref.html<\/p>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\u5730\u5740\uff1a<br \/>\nhttp:\/\/dev.meettea.com\/show-53-1.html<br \/>\nhttp:\/\/code.google.com\/apis\/accounts\/docs\/OAuth_ref.html<br \/>\nhttp:\/\/code.google.com\/apis\/gdata\/faq.html#AuthScopes<br \/>\nhttp:\/\/adaishu.blog.163.com\/blog\/static\/17583128620114974952393\/<\/p>\n<p><a href=\"http:\/\/zduo.me\/blog\/wp-content\/uploads\/2011\/10\/google.zip\">google\u5e33\u6236\u767b\u9304oauth\u7248\u793a\u4f8b\u4ee3\u78bc<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u8981\u7533\u8bf7CONSUMER_KEY\u548cCONSUMER_SECRET\uff0c\u7533\u8bf7\u5730\u5740:https:\/\/www.google.com\/accounts\/ManageDomains OAuth\u9a8c\u8bc1\u7b2c\u4e00\u6b65:Get a Request Token. \u8fd9\u4e2aRequest Token\u662f\u8bf7\u6c42\u4e00\u4e2a\u4ee4\u724c\uff0c\u6765\u5141\u8bb8\u7a0b\u5e8f\u63a5\u5165google\u7684\u670d\u52a1\u3002\u5177\u4f53\u505a\u6cd5\u662f\u53d1\u9001\u4e00\u4e2aHTTP GET\u8bf7\u6c42\u5230https:\/\/www.google.com\/accounts\/OAuthGetRequestToken,\u5e76\u4e14\u5728HTTP\u5934\u91cc\u6709\u4e00\u4e2aAuthorization\u5b57\u6bb5\uff0c\u5b57\u6bb5\u91cc\u7684\u5185\u5bb9\u662fOAuth\u5f00\u5934\uff0c\u52a0\u4e00\u4e2a\u7a7a\u683c\uff0c\u7136\u540e\u662f\u6bcf\u4e2a\u53c2\u6570join\u4e00\u4e2a\u201c,\u201d\u548c\u7a7a\u683c\u3002\u6b64\u5916google\u7684OAuth\u8fd8\u6709\u4e00\u4e2aSCOPE\u53c2\u6570\uff0c\u8fd9\u4e2a\u4e0d\u662f\u6807\u51c6OAuth\u91cc\u7684\u3002 \u6700\u540e\u6ce8\u610f\u7aef\u53e3\u662f443\uff0c\u4e0d\u7136\u4f1a\u6536\u5230\u4e00\u4e2a302;\u5982\u679c\u7a0b\u5e8f\u6709\u95ee\u9898\u4f1a\u6536\u5230\u4e00\u4e2a400\u3002\u5982\u679c\u662f200\uff0c\u5219\u5728\u8fd4\u56de\u7684HTTP BODY\u91cc\u53d6\u5f97$oauth_token,$oauth_token_secret\u4fdd\u5b58\u597d\u8fd9\u4e24\u4e2a\u503c\uff0c\u4e0b\u4e24\u6b65\u8981\u7528\u5230\u3002 \u7b2c\u4e8c\u6b65\u662f\u7528\u6237\u64cd\u4f5c\u90e8\u5206\uff0c\u9700\u8981\u7528\u6237\u6388\u6743\u5e94\u7528\u8bbf\u95eeGOOGLE\u76f8\u5173\u670d\u52a1\u3002 \u4e5f\u5c31\u662fredirect\u5230 www.google.com\/accounts\/OAuthAuthorizeToken?oauth_token=\u521a\u624d\u7684KEY\uff0c\u83b7\u53d6\u7528\u6237\u8054\u7cfb\u4eba\u5217\u8868\u7684scope\u662fhttps:\/\/www.google.com\/m8\/feeds\/\uff0c\u7528\u6237\u5141\u8bb8Access\u540e\u5c31\u4f1a\u8df3\u8f6c\u56de\u521a\u624d\u7684\u9875\u9762\uff0c\u5e76\u4e14\u5728URL\u53c2\u6570\u91cc\u591a\u4e86\u4e00\u4e2a\u53c2\u6570\u3002 \u7b2c\u4e09\u6b65\u662f\u51ed\u521a\u624dURL\u91cc\u9a8c\u8bc1\u7684\u53c2\u6570\u53d1\u9001\u4e00\u4e2aGET\u8bf7\u6c42\u5230https:\/\/www.google.com\/accounts\/OAuthGetAccessToken,\u83b7\u53d6\u63a5\u5165GOOGLE\u670d\u52a1\u7684\u6743\u9650\uff0cHEADER\u91cc\u4ecd\u65e7\u8981\u5305\u542bAuthorization\u5b57\u6bb5\u3002\u5f97\u5230KEY\u548cSECRET\u540e\u66ff\u6362\u521a\u624d\u4e00\u5f00\u59cb\u7684KEY\u548cSECRET\uff0c\u53d1\u9001GET\u8bf7\u6c42\u5230 \u83b7\u53d6\u7528\u6237\u8054\u7cfb\u4eba\u7684scope\uff08https:\/\/www.google.com\/m8\/feeds\/contacts\/default\/thin\uff09\uff0cmax-results\u53c2\u6570\u4ee3\u8868\u83b7\u53d6\u8054\u7cfb\u4eba\u7684\u4e2a\u6570\uff0c\u8fd4\u56de\u7684XML\u5305\u542b&lt;id&gt;\u4e3a\u90ae\u7bb1\uff0c&lt;title&gt;\u91cc\u9762\u542b\u6709\u7528\u6237\u540d\uff0c\u5176\u4e2d\u7b2c\u4e00\u6761\u8bb0\u5f55\u5c31\u662f\u7528\u6237\u672c\u4eba\u7684\u4fe1\u606f\u3002 \u8be6\u7ec6\u7684\u6280\u672f\u6587\u6863\u5728\u8fd9\u91cc http:\/\/code.google.com\/apis\/accounts\/docs\/OAuth_ref.html &nbsp; \u53c2\u8003\u5730\u5740\uff1a http:\/\/dev.meettea.com\/show-53-1.html http:\/\/code.google.com\/apis\/accounts\/docs\/OAuth_ref.html http:\/\/code.google.com\/apis\/gdata\/faq.html#AuthScopes http:\/\/adaishu.blog.163.com\/blog\/static\/17583128620114974952393\/ google\u5e33\u6236\u767b\u9304oauth\u7248\u793a\u4f8b\u4ee3\u78bc &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[113,115,114],"_links":{"self":[{"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/561"}],"collection":[{"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=561"}],"version-history":[{"count":3,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":571,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/561\/revisions\/571"}],"wp:attachment":[{"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zduo.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}