mixiã¢ããªã®ã¦ã¼ã¶ã¼IDãã©ãããã©ã¼ã å ±éåã®ç§»è¡æ¹æ³
mixiãæµ·å¤ã®SNSã¨ãã©ãããã©ã¼ã å ±éåããããããããã®é¢ä¿ã§ãä»ã¾ã§æ°åã®IDã ã£ãã®ããæååã®IDã«åãæ¿ããã¾ãããã®é¢ä¿ã§ãmixiã¢ããªæä¾è ã¯ä»æä¸(2011å¹´10æ)ã«æ°æ¹å¼ã«ç§»è¡ãå¿ è¦ã§ãã
http://developer.mixi.co.jp/news/news_apps/009668.html
ãªããããã¾ãææ³ã¨ãããã°ã§è¦ãããªãã£ãã®ã§ãããæ¹ã¨ãæ¸ãã¦ããã¾ããææããããæ¹ã®åèã«ã©ããã
ã¾ããå¤ããã®ã¯ãID ã ãã§ãAPI ã¯å¤ããã¾ãããä»ã¾ã§ãID ãæååã§ç®¡çãã¦ãã人ã¯ããã¼ã¿ãã¼ã¹ã® ID ãããå·®ãæ¿ãã¦ãã¾ãã°å¯¾å¿å®äºã§ããæ°å¤ã§ãã£ã¦ãã人ã¯ãæååã«ããã°ã©ã ãæ¸ãæããå¿ è¦ãããã¾ãã
ä¸é£ã®è©±ããã¹ãã¢ããªã§ä¸éãç·´ç¿ãã¦ãããæ¬çªã¢ããªã§è¡ã£ã¦ãã ãããã
ã¹ããã1
http://developer.mixi.co.jp/appli/com/change/setting/trans_id/ ã«ããããã«ãIDå¤æAPI ã®ç³è«ããã¾ããã¢ããªã稼åä¸ã®ç¶æ ã§ãã£ã¦ãã¾ã£ã¦ããé常ã¯å¤§ä¸å¤«ã§ãã
ã¹ããã2
ã¾ããæ§ID ã®ä¸è¦§ãå¿ è¦ã§ããin.csv ã¯ï¼1åã®CSVãã¤ã¾ãã«ã³ããªãï¼ã§æ§IDãããããã¨ä¸¦ã¹ãå½¢å¼ã«ãã¾ããã
in.csv ã®ä½ãæ¹ã¯ãã¢ããªæ¬¡ç¬¬ã§ãããåã®å ´åã¯ãPostgreSQL ã§ãããªæãã§ããã
COPY (SELECT mixi_id FROM account_mixi) TO '/tmp/in.csv' CSV;
ã¹ããã3
次ã¯ãæ§ID â æ°ID ã®å¤æã§ããRESTful API ã使ãã¨ãå¤æ表ãæã«å ¥ãã¾ãããããªæãã® Java ã®ã¢ããªã§ããã¾ãããhttp://code.google.com/p/opensocial-java-client/ ãå¿ è¦ã§ãã
java -classpath .;opensocial-1.0.jar;commons-codec-1.3.jar;json_simple-1.1.jar;oauth-20090825.jar MixiOldIdConverter in.csv out.csv failed.csv
ã§å®è¡ãã¾ããä¸åº¦å®è¡ããããout.csv ã failed.csv ã«ä¿ç®¡ããã®ã§ã2åç®ã¯å·®åã ãå®è¡ã§ãã¾ãã1åç®ã¯ãã¢ããªãåããç¶æ³ã§å®è¡ãããã®å¾å¿ è¦ãªããæ°åãã¢ããªãå®è¡ãã¦ããç¶æ ã§è¡ããæå¾ã«ã¢ããªãåæ¢ãã¦å¤æããã¨ãã¢ããªã®åæ¢æéãå°ããåºæ¥ã¾ãã
import org.opensocial.Client; import org.opensocial.Request; import org.opensocial.RequestException; import org.opensocial.Response; import org.opensocial.auth.OAuth2LeggedScheme; import org.opensocial.models.Model; import org.opensocial.services.PeopleService; import java.io.*; import java.util.Date; import java.util.HashSet; public class MixiOldIdConverter { // æ¬çª private static final String consumerKey = "fuga"; private static final String consumerSecret = "barbar"; // ãã¹ã // private static final String consumerKey = "fugaTest"; // private static final String consumerSecret = "barTest"; public static void main(String[] args) throws IOException { File inFile = new File(args[0]); File outFile = new File(args[1]); File failedFile = new File(args[2]); HashSet<String> converted = new HashSet<String>(); readOutFile(outFile, converted); readOutFile(failedFile, converted); BufferedReader reader = new BufferedReader(new FileReader(inFile)); PrintWriter writer = new PrintWriter(new FileWriter(outFile, true)); PrintWriter failedWriter = new PrintWriter(new FileWriter(failedFile, true)); int lineNo = 0; String line; while((line = reader.readLine()) != null) { if (line.length() == 0) continue; if (converted.contains(line)) continue; lineNo++; try { String platformUserId = convert(line); writer.println(line + "," + platformUserId); } catch (Exception e) { //e.printStackTrace(); // ããã³ã¡ã³ãã¢ã¦ããã¦ããã¾ãåé¡ãªã failedWriter.println(line); } if ((lineNo % 10) == 0) System.out.println(lineNo + " " + new Date()); } failedWriter.close(); writer.close(); reader.close(); } private static void readOutFile(File outFile, HashSet<String> converted) throws IOException { if (outFile.exists()) { BufferedReader reader = new BufferedReader(new FileReader(outFile)); String line; while((line = reader.readLine()) != null) { if (line.length() == 0) continue; converted.add(line.split(",")[0]); } reader.close(); } } public static String convert(String oldId) throws IOException, RequestException { OAuth2LeggedScheme authScheme = new OAuth2LeggedScheme(consumerKey, consumerSecret, oldId); Client client = new Client(new MixiProvider(), authScheme); Request viewer = PeopleService.getViewer(); viewer.addParameter("fields", "platformUserId"); Response response = client.send(viewer); Model person = response.getEntry(); return (String) person.getField("platformUserId"); } }
import org.opensocial.providers.Provider; public class MixiProvider extends Provider { public MixiProvider(){ super(); setName("mixi"); setVersion("0.8"); setSignBodyHash(false); setRestEndpoint("http://api.mixi-platform.com/os/0.8/"); } }
ã¹ããã4
- Webã¢ããªãåæ¢ããã
- ãã¼ã¿ãã¼ã¹ã®ããã¯ã¢ãããã¨ãã
- in.csv ã®æçµå½¢ãä½ãã
- å¤æãã¦ãout.csv ã®æçµå½¢ãä½ãã
- ãã®å¾è¨è¼ãã SQL ã¿ãããªæãã§ãæ° ID ã«ç½®ãæããã
- 念ã®ãããå¥ãªãã¡ã¤ã«åã§ãå度ããã¼ã¿ãã¼ã¹ã®ããã¯ã¢ãããã¨ãã
- ãIDã®ãã©ãããã©ã¼ã å ±éå対å¿å®äºããã¯ãªãã¯ããã以éãæ° ID 㧠mixi ã®æ¹ããã¯å¿çãæ¥ãããã«ãªãã¾ãã
- Webã¢ããªãåéããã
CREATE TABLE old_new_mixi_id_map ( old_mixi_id VARCHAR(255) PRIMARY KEY, new_mixi_id VARCHAR(255) NOT NULL ); COPY old_new_mixi_id_map FROM '/tmp/out.csv' CSV; UPDATE account_mixi SET mixi_id = (SELECT new_mixi_id FROM old_new_mixi_id_map WHERE old_new_mixi_id_map.old_mixi_id = account_mixi.mixi_id) WHERE mixi_id in (SELECT old_mixi_id FROM old_new_mixi_id_map);
å ´åã«ãã£ã¦ã¯ãä»ã«ãé¢é£ãããã¼ãã«ã®æ å ±ãåé¤ããå ´åãã¢ããªã«ãã£ã¦ã¯ããã¨æãã¾ããï¼åã®å ´åã¯ãä»ã«2ã«æããã¼ã¿ãåé¤ãã¾ããï¼